[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> dashboard.php (source)

   1  <?php
   2  /**
   3   * WordPress Dashboard Widget Administration Screen API
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /**
  10   * Registers dashboard widgets.
  11   *
  12   * Handles POST data, sets up filters.
  13   *
  14   * @since 2.5.0
  15   *
  16   * @global array $wp_registered_widgets
  17   * @global array $wp_registered_widget_controls
  18   * @global callable[] $wp_dashboard_control_callbacks
  19   */
  20  function wp_dashboard_setup() {
  21      global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
  22  
  23      $screen = get_current_screen();
  24  
  25      /* Register Widgets and Controls */
  26      $wp_dashboard_control_callbacks = array();
  27  
  28      // Browser version
  29      $check_browser = wp_check_browser_version();
  30  
  31      if ( $check_browser && $check_browser['upgrade'] ) {
  32          add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
  33  
  34          if ( $check_browser['insecure'] ) {
  35              wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
  36          } else {
  37              wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
  38          }
  39      }
  40  
  41      // PHP Version.
  42      $check_php = wp_check_php_version();
  43  
  44      if ( $check_php && current_user_can( 'update_php' ) ) {
  45          // If "not acceptable" the widget will be shown.
  46          if ( isset( $check_php['is_acceptable'] ) && ! $check_php['is_acceptable'] ) {
  47              add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' );
  48  
  49              if ( $check_php['is_lower_than_future_minimum'] ) {
  50                  wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' );
  51              } else {
  52                  wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' );
  53              }
  54          }
  55      }
  56  
  57      // Site Health.
  58      if ( current_user_can( 'view_site_health_checks' ) && ! is_network_admin() ) {
  59          if ( ! class_exists( 'WP_Site_Health' ) ) {
  60              require_once  ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
  61          }
  62  
  63          WP_Site_Health::get_instance();
  64  
  65          wp_enqueue_style( 'site-health' );
  66          wp_enqueue_script( 'site-health' );
  67  
  68          wp_add_dashboard_widget( 'dashboard_site_health', __( 'Site Health Status' ), 'wp_dashboard_site_health' );
  69      }
  70  
  71      // Right Now.
  72      if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
  73          wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
  74      }
  75  
  76      if ( is_network_admin() ) {
  77          wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
  78      }
  79  
  80      // Activity Widget.
  81      if ( is_blog_admin() ) {
  82          wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
  83      }
  84  
  85      // QuickPress Widget.
  86      if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
  87          $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) );
  88          wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
  89      }
  90  
  91      // WordPress Events and News.
  92      wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );
  93  
  94      if ( is_network_admin() ) {
  95  
  96          /**
  97           * Fires after core widgets for the Network Admin dashboard have been registered.
  98           *
  99           * @since 3.1.0
 100           */
 101          do_action( 'wp_network_dashboard_setup' );
 102  
 103          /**
 104           * Filters the list of widgets to load for the Network Admin dashboard.
 105           *
 106           * @since 3.1.0
 107           *
 108           * @param string[] $dashboard_widgets An array of dashboard widget IDs.
 109           */
 110          $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
 111      } elseif ( is_user_admin() ) {
 112  
 113          /**
 114           * Fires after core widgets for the User Admin dashboard have been registered.
 115           *
 116           * @since 3.1.0
 117           */
 118          do_action( 'wp_user_dashboard_setup' );
 119  
 120          /**
 121           * Filters the list of widgets to load for the User Admin dashboard.
 122           *
 123           * @since 3.1.0
 124           *
 125           * @param string[] $dashboard_widgets An array of dashboard widget IDs.
 126           */
 127          $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
 128      } else {
 129  
 130          /**
 131           * Fires after core widgets for the admin dashboard have been registered.
 132           *
 133           * @since 2.5.0
 134           */
 135          do_action( 'wp_dashboard_setup' );
 136  
 137          /**
 138           * Filters the list of widgets to load for the admin dashboard.
 139           *
 140           * @since 2.5.0
 141           *
 142           * @param string[] $dashboard_widgets An array of dashboard widget IDs.
 143           */
 144          $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
 145      }
 146  
 147      foreach ( $dashboard_widgets as $widget_id ) {
 148          $name = empty( $wp_registered_widgets[ $widget_id ]['all_link'] ) ? $wp_registered_widgets[ $widget_id ]['name'] : $wp_registered_widgets[ $widget_id ]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __( 'View all' ) . '</a>';
 149          wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] );
 150      }
 151  
 152      if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
 153          check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
 154          ob_start(); // Hack - but the same hack wp-admin/widgets.php uses.
 155          wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
 156          ob_end_clean();
 157          wp_redirect( remove_query_arg( 'edit' ) );
 158          exit;
 159      }
 160  
 161      /** This action is documented in wp-admin/includes/meta-boxes.php */
 162      do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
 163  
 164      /** This action is documented in wp-admin/includes/meta-boxes.php */
 165      do_action( 'do_meta_boxes', $screen->id, 'side', '' );
 166  }
 167  
 168  /**
 169   * Adds a new dashboard widget.
 170   *
 171   * @since 2.7.0
 172   * @since 5.6.0 The `$context` and `$priority` parameters were added.
 173   *
 174   * @global callable[] $wp_dashboard_control_callbacks
 175   *
 176   * @param string   $widget_id        Widget ID  (used in the 'id' attribute for the widget).
 177   * @param string   $widget_name      Title of the widget.
 178   * @param callable $callback         Function that fills the widget with the desired content.
 179   *                                   The function should echo its output.
 180   * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
 181   * @param array    $callback_args    Optional. Data that should be set as the $args property of the widget array
 182   *                                   (which is the second parameter passed to your callback). Default null.
 183   * @param string   $context          Optional. The context within the screen where the box should display.
 184   *                                   Accepts 'normal', 'side', 'column3', or 'column4'. Default 'normal'.
 185   * @param string   $priority         Optional. The priority within the context where the box should show.
 186   *                                   Accepts 'high', 'core', 'default', or 'low'. Default 'core'.
 187   */
 188  function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core' ) {
 189      global $wp_dashboard_control_callbacks;
 190  
 191      $screen = get_current_screen();
 192  
 193      $private_callback_args = array( '__widget_basename' => $widget_name );
 194  
 195      if ( is_null( $callback_args ) ) {
 196          $callback_args = $private_callback_args;
 197      } elseif ( is_array( $callback_args ) ) {
 198          $callback_args = array_merge( $callback_args, $private_callback_args );
 199      }
 200  
 201      if ( $control_callback && is_callable( $control_callback ) && current_user_can( 'edit_dashboard' ) ) {
 202          $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback;
 203  
 204          if ( isset( $_GET['edit'] ) && $widget_id === $_GET['edit'] ) {
 205              list($url)    = explode( '#', add_query_arg( 'edit', false ), 2 );
 206              $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
 207              $callback     = '_wp_dashboard_control_callback';
 208          } else {
 209              list($url)    = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
 210              $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
 211          }
 212      }
 213  
 214      $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
 215  
 216      if ( in_array( $widget_id, $side_widgets, true ) ) {
 217          $context = 'side';
 218      }
 219  
 220      $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
 221  
 222      if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
 223          $priority = 'high';
 224      }
 225  
 226      if ( empty( $context ) ) {
 227          $context = 'normal';
 228      }
 229  
 230      if ( empty( $priority ) ) {
 231          $priority = 'core';
 232      }
 233  
 234      add_meta_box( $widget_id, $widget_name, $callback, $screen, $context, $priority, $callback_args );
 235  }
 236  
 237  /**
 238   * Outputs controls for the current dashboard widget.
 239   *
 240   * @access private
 241   * @since 2.7.0
 242   *
 243   * @param mixed $dashboard
 244   * @param array $meta_box
 245   */
 246  function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
 247      echo '<form method="post" class="dashboard-widget-control-form wp-clearfix">';
 248      wp_dashboard_trigger_widget_control( $meta_box['id'] );
 249      wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
 250      echo '<input type="hidden" name="widget_id" value="' . esc_attr( $meta_box['id'] ) . '" />';
 251      submit_button( __( 'Save Changes' ) );
 252      echo '</form>';
 253  }
 254  
 255  /**
 256   * Displays the dashboard.
 257   *
 258   * @since 2.5.0
 259   */
 260  function wp_dashboard() {
 261      $screen      = get_current_screen();
 262      $columns     = absint( $screen->get_columns() );
 263      $columns_css = '';
 264  
 265      if ( $columns ) {
 266          $columns_css = " columns-$columns";
 267      }
 268      ?>
 269  <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
 270      <div id="postbox-container-1" class="postbox-container">
 271      <?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
 272      </div>
 273      <div id="postbox-container-2" class="postbox-container">
 274      <?php do_meta_boxes( $screen->id, 'side', '' ); ?>
 275      </div>
 276      <div id="postbox-container-3" class="postbox-container">
 277      <?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
 278      </div>
 279      <div id="postbox-container-4" class="postbox-container">
 280      <?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
 281      </div>
 282  </div>
 283  
 284      <?php
 285      wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
 286      wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
 287  }
 288  
 289  //
 290  // Dashboard Widgets.
 291  //
 292  
 293  /**
 294   * Dashboard widget that displays some basic stats about the site.
 295   *
 296   * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
 297   *
 298   * @since 2.7.0
 299   */
 300  function wp_dashboard_right_now() {
 301      ?>
 302      <div class="main">
 303      <ul>
 304      <?php
 305      // Posts and Pages.
 306      foreach ( array( 'post', 'page' ) as $post_type ) {
 307          $num_posts = wp_count_posts( $post_type );
 308  
 309          if ( $num_posts && $num_posts->publish ) {
 310              if ( 'post' === $post_type ) {
 311                  /* translators: %s: Number of posts. */
 312                  $text = _n( '%s Published post', '%s Published posts', $num_posts->publish );
 313              } else {
 314                  /* translators: %s: Number of pages. */
 315                  $text = _n( '%s Published page', '%s Published pages', $num_posts->publish );
 316              }
 317  
 318              $text             = sprintf( $text, number_format_i18n( $num_posts->publish ) );
 319              $post_type_object = get_post_type_object( $post_type );
 320  
 321              if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
 322                  $url = add_query_arg(
 323                      array(
 324                          'post_status' => 'publish',
 325                          'post_type'   => $post_type,
 326                      ),
 327                      admin_url( 'edit.php' )
 328                  );
 329                  printf( '<li class="%1$s-count"><a href="%2$s">%3$s</a></li>', $post_type, esc_url( $url ), esc_html( $text ) );
 330              } else {
 331                  printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
 332              }
 333          }
 334      }
 335  
 336      // Comments.
 337      $num_comm = wp_count_comments();
 338  
 339      if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
 340          /* translators: %s: Number of comments. */
 341          $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
 342          ?>
 343          <li class="comment-count">
 344              <a href="edit-comments.php"><?php echo $text; ?></a>
 345          </li>
 346          <?php
 347          $moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated );
 348          /* translators: %s: Number of comments. */
 349          $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );
 350          ?>
 351          <li class="comment-mod-count<?php echo ! $num_comm->moderated ? ' hidden' : ''; ?>">
 352              <a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a>
 353          </li>
 354          <?php
 355      }
 356  
 357      /**
 358       * Filters the array of extra elements to list in the 'At a Glance'
 359       * dashboard widget.
 360       *
 361       * Prior to 3.8.0, the widget was named 'Right Now'. Each element
 362       * is wrapped in list-item tags on output.
 363       *
 364       * @since 3.8.0
 365       *
 366       * @param string[] $items Array of extra 'At a Glance' widget items.
 367       */
 368      $elements = apply_filters( 'dashboard_glance_items', array() );
 369  
 370      if ( $elements ) {
 371          echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
 372      }
 373  
 374      ?>
 375      </ul>
 376      <?php
 377      update_right_now_message();
 378  
 379      // Check if search engines are asked not to index this site.
 380      if ( ! is_network_admin() && ! is_user_admin()
 381          && current_user_can( 'manage_options' ) && ! get_option( 'blog_public' )
 382      ) {
 383  
 384          /**
 385           * Filters the link title attribute for the 'Search engines discouraged'
 386           * message displayed in the 'At a Glance' dashboard widget.
 387           *
 388           * Prior to 3.8.0, the widget was named 'Right Now'.
 389           *
 390           * @since 3.0.0
 391           * @since 4.5.0 The default for `$title` was updated to an empty string.
 392           *
 393           * @param string $title Default attribute text.
 394           */
 395          $title = apply_filters( 'privacy_on_link_title', '' );
 396  
 397          /**
 398           * Filters the link label for the 'Search engines discouraged' message
 399           * displayed in the 'At a Glance' dashboard widget.
 400           *
 401           * Prior to 3.8.0, the widget was named 'Right Now'.
 402           *
 403           * @since 3.0.0
 404           *
 405           * @param string $content Default text.
 406           */
 407          $content = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) );
 408  
 409          $title_attr = '' === $title ? '' : " title='$title'";
 410  
 411          echo "<p class='search-engines-info'><a href='options-reading.php'$title_attr>$content</a></p>";
 412      }
 413      ?>
 414      </div>
 415      <?php
 416      /*
 417       * activity_box_end has a core action, but only prints content when multisite.
 418       * Using an output buffer is the only way to really check if anything's displayed here.
 419       */
 420      ob_start();
 421  
 422      /**
 423       * Fires at the end of the 'At a Glance' dashboard widget.
 424       *
 425       * Prior to 3.8.0, the widget was named 'Right Now'.
 426       *
 427       * @since 2.5.0
 428       */
 429      do_action( 'rightnow_end' );
 430  
 431      /**
 432       * Fires at the end of the 'At a Glance' dashboard widget.
 433       *
 434       * Prior to 3.8.0, the widget was named 'Right Now'.
 435       *
 436       * @since 2.0.0
 437       */
 438      do_action( 'activity_box_end' );
 439  
 440      $actions = ob_get_clean();
 441  
 442      if ( ! empty( $actions ) ) :
 443          ?>
 444      <div class="sub">
 445          <?php echo $actions; ?>
 446      </div>
 447          <?php
 448      endif;
 449  }
 450  
 451  /**
 452   * @since 3.1.0
 453   */
 454  function wp_network_dashboard_right_now() {
 455      $actions = array();
 456  
 457      if ( current_user_can( 'create_sites' ) ) {
 458          $actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>';
 459      }
 460      if ( current_user_can( 'create_users' ) ) {
 461          $actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>';
 462      }
 463  
 464      $c_users = get_user_count();
 465      $c_blogs = get_blog_count();
 466  
 467      /* translators: %s: Number of users on the network. */
 468      $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
 469      /* translators: %s: Number of sites on the network. */
 470      $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
 471  
 472      /* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network. */
 473      $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
 474  
 475      if ( $actions ) {
 476          echo '<ul class="subsubsub">';
 477          foreach ( $actions as $class => $action ) {
 478              $actions[ $class ] = "\t<li class='$class'>$action";
 479          }
 480          echo implode( " |</li>\n", $actions ) . "</li>\n";
 481          echo '</ul>';
 482      }
 483      ?>
 484      <br class="clear" />
 485  
 486      <p class="youhave"><?php echo $sentence; ?></p>
 487  
 488  
 489      <?php
 490          /**
 491           * Fires in the Network Admin 'Right Now' dashboard widget
 492           * just before the user and site search form fields.
 493           *
 494           * @since MU (3.0.0)
 495           */
 496          do_action( 'wpmuadminresult' );
 497      ?>
 498  
 499      <form action="<?php echo esc_url( network_admin_url( 'users.php' ) ); ?>" method="get">
 500          <p>
 501              <label class="screen-reader-text" for="search-users">
 502                  <?php
 503                  /* translators: Hidden accessibility text. */
 504                  _e( 'Search Users' );
 505                  ?>
 506              </label>
 507              <input type="search" name="s" value="" size="30" autocomplete="off" id="search-users" />
 508              <?php submit_button( __( 'Search Users' ), '', false, false, array( 'id' => 'submit_users' ) ); ?>
 509          </p>
 510      </form>
 511  
 512      <form action="<?php echo esc_url( network_admin_url( 'sites.php' ) ); ?>" method="get">
 513          <p>
 514              <label class="screen-reader-text" for="search-sites">
 515                  <?php
 516                  /* translators: Hidden accessibility text. */
 517                  _e( 'Search Sites' );
 518                  ?>
 519              </label>
 520              <input type="search" name="s" value="" size="30" autocomplete="off" id="search-sites" />
 521              <?php submit_button( __( 'Search Sites' ), '', false, false, array( 'id' => 'submit_sites' ) ); ?>
 522          </p>
 523      </form>
 524      <?php
 525      /**
 526       * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
 527       *
 528       * @since MU (3.0.0)
 529       */
 530      do_action( 'mu_rightnow_end' );
 531  
 532      /**
 533       * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
 534       *
 535       * @since MU (3.0.0)
 536       */
 537      do_action( 'mu_activity_box_end' );
 538  }
 539  
 540  /**
 541   * Displays the Quick Draft widget.
 542   *
 543   * @since 3.8.0
 544   * @since 7.1.0 Added $notice_type parameter.
 545   *
 546   * @global int $post_ID
 547   *
 548   * @param string|false $message     Optional. Error or success message. Default false.
 549   * @param string       $notice_type Optional. Admin notice type. Default 'error'.
 550   */
 551  function wp_dashboard_quick_press( $message = false, $notice_type = 'error' ) {
 552      global $post_ID;
 553  
 554      if ( ! current_user_can( 'edit_posts' ) ) {
 555          return;
 556      }
 557  
 558      // Check if a new auto-draft (= no new post_ID) is needed or if the old can be used.
 559      $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID.
 560  
 561      if ( $last_post_id ) {
 562          $post = get_post( $last_post_id );
 563  
 564          if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore.
 565              $post = get_default_post_to_edit( 'post', true );
 566              update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
 567          } else {
 568              $post->post_title = ''; // Remove the auto draft title.
 569          }
 570      } else {
 571          $post            = get_default_post_to_edit( 'post', true );
 572          $user_id         = get_current_user_id();
 573          $user_blogs      = get_blogs_of_user( $user_id );
 574          $current_blog_id = get_current_blog_id();
 575  
 576          // Don't create an option if this is a super admin who does not belong to this site.
 577          if ( isset( $user_blogs[ $current_blog_id ] ) ) {
 578              update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
 579          }
 580      }
 581  
 582      $post_ID = (int) $post->ID;
 583      ?>
 584  
 585      <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="hide-if-no-js">
 586  
 587          <?php
 588          if ( $message ) {
 589              wp_admin_notice(
 590                  $message,
 591                  array(
 592                      'type'       => $notice_type,
 593                      'attributes' => array(
 594                          'role' => 'alert',
 595                      ),
 596                  )
 597              );
 598          }
 599          ?>
 600  
 601          <div class="input-text-wrap" id="title-wrap">
 602              <label for="title">
 603                  <?php
 604                  /** This filter is documented in wp-admin/edit-form-advanced.php */
 605                  echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
 606                  ?>
 607              </label>
 608              <input type="text" name="post_title" id="title" autocomplete="off" />
 609          </div>
 610  
 611          <div class="textarea-wrap" id="description-wrap">
 612              <label for="content"><?php _e( 'Content' ); ?></label>
 613              <textarea name="content" id="content" placeholder="<?php esc_attr_e( 'What&#8217;s on your mind?' ); ?>" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea>
 614          </div>
 615  
 616          <p class="submit">
 617              <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
 618              <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
 619              <input type="hidden" name="post_type" value="post" />
 620              <?php wp_nonce_field( 'add-post' ); ?>
 621              <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
 622              <br class="clear" />
 623          </p>
 624  
 625      </form>
 626      <?php
 627      wp_dashboard_recent_drafts();
 628  }
 629  
 630  /**
 631   * Show recent drafts of the user on the dashboard.
 632   *
 633   * @since 2.7.0
 634   *
 635   * @param WP_Post[]|false $drafts Optional. Array of posts to display. Default false.
 636   */
 637  function wp_dashboard_recent_drafts( $drafts = false ) {
 638      if ( ! $drafts ) {
 639          $query_args = array(
 640              'post_type'      => 'post',
 641              'post_status'    => 'draft',
 642              'author'         => get_current_user_id(),
 643              'posts_per_page' => 4,
 644              'orderby'        => 'modified',
 645              'order'          => 'DESC',
 646          );
 647  
 648          /**
 649           * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
 650           *
 651           * @since 4.4.0
 652           *
 653           * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
 654           */
 655          $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );
 656  
 657          $drafts = get_posts( $query_args );
 658          if ( ! $drafts ) {
 659              echo '<div class="no-drafts">';
 660              echo '<p>' . __( 'There are no recent drafts.' ) . '</p>';
 661              echo '</div>';
 662              return;
 663          }
 664      }
 665  
 666      echo '<div class="drafts">';
 667  
 668      if ( count( $drafts ) > 3 ) {
 669          printf(
 670              '<p class="view-all"><a href="%s">%s</a></p>' . "\n",
 671              esc_url( admin_url( 'edit.php?post_status=draft' ) ),
 672              __( 'View all drafts' )
 673          );
 674      }
 675  
 676      echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n";
 677      echo '<ul>';
 678  
 679      /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
 680      $draft_length = (int) _x( '10', 'draft_length' );
 681  
 682      $drafts = array_slice( $drafts, 0, 3 );
 683      foreach ( $drafts as $draft ) {
 684          $url   = get_edit_post_link( $draft->ID );
 685          $title = _draft_or_post_title( $draft->ID );
 686  
 687          echo "<li>\n";
 688          printf(
 689              '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
 690              esc_url( $url ),
 691              /* translators: %s: Post title. */
 692              esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
 693              esc_html( $title ),
 694              get_the_time( 'c', $draft ),
 695              get_the_time( __( 'F j, Y' ), $draft )
 696          );
 697  
 698          $the_content = wp_trim_words( $draft->post_content, $draft_length );
 699  
 700          if ( $the_content ) {
 701              echo '<p class="draft-content">' . $the_content . '</p>';
 702          }
 703          echo "</li>\n";
 704      }
 705  
 706      echo "</ul>\n";
 707      echo '</div>';
 708  }
 709  
 710  /**
 711   * Outputs a row for the Recent Comments widget.
 712   *
 713   * @access private
 714   * @since 2.7.0
 715   *
 716   * @global WP_Comment $comment Global comment object.
 717   *
 718   * @param WP_Comment $comment   The current comment.
 719   * @param bool       $show_date Optional. Whether to display the date.
 720   */
 721  function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
 722      $GLOBALS['comment'] = clone $comment;
 723  
 724      if ( $comment->comment_post_ID > 0 ) {
 725          $comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
 726          $comment_post_url   = get_the_permalink( $comment->comment_post_ID );
 727          $comment_post_link  = '<a href="' . esc_url( $comment_post_url ) . '">' . $comment_post_title . '</a>';
 728      } else {
 729          $comment_post_link = '';
 730      }
 731  
 732      $actions_string = '';
 733      if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
 734          // Pre-order it: Approve | Reply | Edit | Spam | Trash.
 735          $actions = array(
 736              'approve'   => '',
 737              'unapprove' => '',
 738              'reply'     => '',
 739              'edit'      => '',
 740              'spam'      => '',
 741              'trash'     => '',
 742              'delete'    => '',
 743              'view'      => '',
 744          );
 745  
 746          $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'approve-comment_' . $comment->comment_ID ) );
 747          $del_nonce     = esc_html( '_wpnonce=' . wp_create_nonce( 'delete-comment_' . $comment->comment_ID ) );
 748  
 749          $action_string = 'comment.php?action=%s&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . '&%s';
 750  
 751          $approve_url   = sprintf( $action_string, 'approvecomment', $approve_nonce );
 752          $unapprove_url = sprintf( $action_string, 'unapprovecomment', $approve_nonce );
 753          $spam_url      = sprintf( $action_string, 'spamcomment', $del_nonce );
 754          $trash_url     = sprintf( $action_string, 'trashcomment', $del_nonce );
 755          $delete_url    = sprintf( $action_string, 'deletecomment', $del_nonce );
 756  
 757          $actions['approve'] = sprintf(
 758              '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
 759              esc_url( $approve_url ),
 760              "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
 761              esc_attr__( 'Approve this comment' ),
 762              __( 'Approve' )
 763          );
 764  
 765          $actions['unapprove'] = sprintf(
 766              '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
 767              esc_url( $unapprove_url ),
 768              "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
 769              esc_attr__( 'Unapprove this comment' ),
 770              __( 'Unapprove' )
 771          );
 772  
 773          $actions['edit'] = sprintf(
 774              '<a href="%s" aria-label="%s">%s</a>',
 775              "comment.php?action=editcomment&amp;c={$comment->comment_ID}",
 776              esc_attr__( 'Edit this comment' ),
 777              __( 'Edit' )
 778          );
 779  
 780          $actions['reply'] = sprintf(
 781              '<button type="button" onclick="window.commentReply && commentReply.open(\'%s\',\'%s\');" class="vim-r button-link hide-if-no-js" aria-label="%s">%s</button>',
 782              $comment->comment_ID,
 783              $comment->comment_post_ID,
 784              esc_attr__( 'Reply to this comment' ),
 785              /* translators: Comment reply button text. */
 786              _x( 'Reply', 'verb' )
 787          );
 788  
 789          $actions['spam'] = sprintf(
 790              '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 791              esc_url( $spam_url ),
 792              "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
 793              esc_attr__( 'Mark this comment as spam' ),
 794              /* translators: "Mark as spam" link. */
 795              _x( 'Spam', 'verb' )
 796          );
 797  
 798          if ( ! EMPTY_TRASH_DAYS ) {
 799              $actions['delete'] = sprintf(
 800                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 801                  esc_url( $delete_url ),
 802                  "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
 803                  esc_attr__( 'Delete this comment permanently' ),
 804                  __( 'Delete Permanently' )
 805              );
 806          } else {
 807              $actions['trash'] = sprintf(
 808                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 809                  esc_url( $trash_url ),
 810                  "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
 811                  esc_attr__( 'Move this comment to the Trash' ),
 812                  _x( 'Trash', 'verb' )
 813              );
 814          }
 815  
 816          $actions['view'] = sprintf(
 817              '<a class="comment-link" href="%s" aria-label="%s">%s</a>',
 818              esc_url( get_comment_link( $comment ) ),
 819              esc_attr__( 'View this comment' ),
 820              __( 'View' )
 821          );
 822  
 823          /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
 824          $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
 825  
 826          $i = 0;
 827  
 828          foreach ( $actions as $action => $link ) {
 829              ++$i;
 830  
 831              if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
 832                  || 1 === $i
 833              ) {
 834                  $separator = '';
 835              } else {
 836                  $separator = ' | ';
 837              }
 838  
 839              // Reply and quickedit need a hide-if-no-js span.
 840              if ( 'reply' === $action || 'quickedit' === $action ) {
 841                  $action .= ' hide-if-no-js';
 842              }
 843  
 844              if ( 'view' === $action && '1' !== $comment->comment_approved ) {
 845                  $action .= ' hidden';
 846              }
 847  
 848              $actions_string .= "<span class='$action'>{$separator}{$link}</span>";
 849          }
 850      }
 851      ?>
 852  
 853          <li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>
 854  
 855              <?php
 856              $comment_row_class = '';
 857  
 858              if ( get_option( 'show_avatars' ) ) {
 859                  echo get_avatar( $comment, 50, 'mystery' );
 860                  $comment_row_class .= ' has-avatar';
 861              }
 862              ?>
 863  
 864              <?php if ( ! $comment->comment_type || 'comment' === $comment->comment_type ) : ?>
 865  
 866              <div class="dashboard-comment-wrap has-row-actions <?php echo $comment_row_class; ?>">
 867              <p class="comment-meta">
 868                  <?php
 869                  // Comments might not have a post they relate to, e.g. programmatically created ones.
 870                  if ( $comment_post_link ) {
 871                      printf(
 872                          /* translators: 1: Comment author, 2: Post link, 3: Notification if the comment is pending. */
 873                          __( 'From %1$s on %2$s %3$s' ),
 874                          '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
 875                          $comment_post_link,
 876                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 877                      );
 878                  } else {
 879                      printf(
 880                          /* translators: 1: Comment author, 2: Notification if the comment is pending. */
 881                          __( 'From %1$s %2$s' ),
 882                          '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
 883                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 884                      );
 885                  }
 886                  ?>
 887              </p>
 888  
 889                  <?php
 890              else :
 891                  switch ( $comment->comment_type ) {
 892                      case 'pingback':
 893                          $type = __( 'Pingback' );
 894                          break;
 895                      case 'trackback':
 896                          $type = __( 'Trackback' );
 897                          break;
 898                      default:
 899                          $type = ucwords( $comment->comment_type );
 900                  }
 901                  $type = esc_html( $type );
 902                  ?>
 903              <div class="dashboard-comment-wrap has-row-actions">
 904              <p class="comment-meta">
 905                  <?php
 906                  // Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
 907                  if ( $comment_post_link ) {
 908                      printf(
 909                          /* translators: 1: Type of comment, 2: Post link, 3: Notification if the comment is pending. */
 910                          _x( '%1$s on %2$s %3$s', 'dashboard' ),
 911                          "<strong>$type</strong>",
 912                          $comment_post_link,
 913                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 914                      );
 915                  } else {
 916                      printf(
 917                          /* translators: 1: Type of comment, 2: Notification if the comment is pending. */
 918                          _x( '%1$s %2$s', 'dashboard' ),
 919                          "<strong>$type</strong>",
 920                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 921                      );
 922                  }
 923                  ?>
 924              </p>
 925              <p class="comment-author"><?php comment_author_link( $comment ); ?></p>
 926  
 927              <?php endif; // comment_type ?>
 928              <blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote>
 929              <?php if ( $actions_string ) : ?>
 930              <p class="row-actions"><?php echo $actions_string; ?></p>
 931              <?php endif; ?>
 932              </div>
 933          </li>
 934      <?php
 935      $GLOBALS['comment'] = null;
 936  }
 937  
 938  /**
 939   * Outputs the Activity widget.
 940   *
 941   * Callback function for {@see 'dashboard_activity'}.
 942   *
 943   * @since 3.8.0
 944   */
 945  function wp_dashboard_site_activity() {
 946  
 947      echo '<div id="activity-widget">';
 948  
 949      $future_posts = wp_dashboard_recent_posts(
 950          array(
 951              'max'    => 5,
 952              'status' => 'future',
 953              'order'  => 'ASC',
 954              'title'  => __( 'Publishing Soon' ),
 955              'id'     => 'future-posts',
 956          )
 957      );
 958      $recent_posts = wp_dashboard_recent_posts(
 959          array(
 960              'max'    => 5,
 961              'status' => 'publish',
 962              'order'  => 'DESC',
 963              'title'  => __( 'Recently Published' ),
 964              'id'     => 'published-posts',
 965          )
 966      );
 967  
 968      $recent_comments = wp_dashboard_recent_comments();
 969  
 970      if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
 971          echo '<div class="no-activity">';
 972          echo '<p>' . __( 'No activity yet!' ) . '</p>';
 973          echo '</div>';
 974      }
 975  
 976      echo '</div>';
 977  }
 978  
 979  /**
 980   * Generates Publishing Soon and Recently Published sections.
 981   *
 982   * @since 3.8.0
 983   *
 984   * @param array $args {
 985   *     An array of query and display arguments.
 986   *
 987   *     @type int    $max     Number of posts to display.
 988   *     @type string $status  Post status.
 989   *     @type string $order   Designates ascending ('ASC') or descending ('DESC') order.
 990   *     @type string $title   Section title.
 991   *     @type string $id      The container id.
 992   * }
 993   * @return bool False if no posts were found. True otherwise.
 994   */
 995  function wp_dashboard_recent_posts( $args ) {
 996      $query_args = array(
 997          'post_type'      => 'post',
 998          'post_status'    => $args['status'],
 999          'orderby'        => 'date',
1000          'order'          => $args['order'],
1001          'posts_per_page' => (int) $args['max'],
1002          'no_found_rows'  => true,
1003          'cache_results'  => true,
1004          'perm'           => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
1005      );
1006  
1007      /**
1008       * Filters the query arguments used for the Recent Posts widget.
1009       *
1010       * @since 4.2.0
1011       *
1012       * @param array $query_args The arguments passed to WP_Query to produce the list of posts.
1013       */
1014      $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args );
1015  
1016      $posts = new WP_Query( $query_args );
1017  
1018      if ( $posts->have_posts() ) {
1019  
1020          echo '<div id="' . $args['id'] . '" class="activity-block">';
1021  
1022          echo '<h3>' . $args['title'] . '</h3>';
1023  
1024          echo '<ul>';
1025  
1026          $today    = current_time( 'Y-m-d' );
1027          $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
1028          $year     = current_time( 'Y' );
1029  
1030          while ( $posts->have_posts() ) {
1031              $posts->the_post();
1032  
1033              $time = get_the_time( 'U' );
1034  
1035              if ( ! is_int( $time ) ) {
1036                  /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */
1037                  $date = get_the_date( __( 'M jS Y' ) );
1038              } elseif ( gmdate( 'Y-m-d', $time ) === $today ) {
1039                  $date = __( 'Today' );
1040              } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) {
1041                  $date = __( 'Tomorrow' );
1042              } elseif ( gmdate( 'Y', $time ) !== $year ) {
1043                  /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */
1044                  $date = date_i18n( __( 'M jS Y' ), $time );
1045              } else {
1046                  /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/manual/datetime.format.php */
1047                  $date = date_i18n( __( 'M jS' ), $time );
1048              }
1049  
1050              // Use the post edit link for those who can edit, the permalink otherwise.
1051              $recent_post_link = current_user_can( 'edit_post', get_the_ID() ) ? get_edit_post_link() : get_permalink();
1052  
1053              $draft_or_post_title = _draft_or_post_title();
1054              printf(
1055                  '<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
1056                  /* translators: 1: Relative date, 2: Time. */
1057                  sprintf( _x( '%1$s, %2$s', 'dashboard' ), $date, get_the_time() ),
1058                  $recent_post_link,
1059                  /* translators: %s: Post title. */
1060                  esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $draft_or_post_title ) ),
1061                  $draft_or_post_title
1062              );
1063          }
1064  
1065          echo '</ul>';
1066          echo '</div>';
1067  
1068      } else {
1069          return false;
1070      }
1071  
1072      wp_reset_postdata();
1073  
1074      return true;
1075  }
1076  
1077  /**
1078   * Show Comments section.
1079   *
1080   * @since 3.8.0
1081   *
1082   * @param int $total_items Optional. Number of comments to query. Default 5.
1083   * @return bool False if no comments were found. True otherwise.
1084   */
1085  function wp_dashboard_recent_comments( $total_items = 5 ) {
1086      // Select all comment types and filter out spam later for better query performance.
1087      $comments = array();
1088  
1089      $comments_query = array(
1090          'number' => $total_items * 5,
1091          'offset' => 0,
1092      );
1093  
1094      if ( ! current_user_can( 'edit_posts' ) ) {
1095          $comments_query['status'] = 'approve';
1096      }
1097  
1098      $comments_count = 0;
1099      do {
1100          $possible = get_comments( $comments_query );
1101  
1102          if ( empty( $possible ) || ! is_array( $possible ) ) {
1103              break;
1104          }
1105  
1106          foreach ( $possible as $comment ) {
1107              if ( ! current_user_can( 'edit_post', $comment->comment_post_ID )
1108                  && ( post_password_required( $comment->comment_post_ID )
1109                      || ! current_user_can( 'read_post', $comment->comment_post_ID ) )
1110              ) {
1111                  // The user has no access to the post and thus cannot see the comments.
1112                  continue;
1113              }
1114  
1115              $comments[]     = $comment;
1116              $comments_count = count( $comments );
1117  
1118              if ( $comments_count === $total_items ) {
1119                  break 2;
1120              }
1121          }
1122  
1123          $comments_query['offset'] += $comments_query['number'];
1124          $comments_query['number']  = $total_items * 10;
1125      } while ( $comments_count < $total_items );
1126  
1127      if ( $comments ) {
1128          echo '<div id="latest-comments" class="activity-block table-view-list">';
1129          echo '<h3>' . __( 'Recent Comments' ) . '</h3>';
1130  
1131          echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
1132          foreach ( $comments as $comment ) {
1133              _wp_dashboard_recent_comments_row( $comment );
1134          }
1135          echo '</ul>';
1136  
1137          if ( current_user_can( 'edit_posts' ) ) {
1138              echo '<h3 class="screen-reader-text">' .
1139                  /* translators: Hidden accessibility text. */
1140                  __( 'View more comments' ) .
1141              '</h3>';
1142              _get_list_table( 'WP_Comments_List_Table' )->views();
1143          }
1144  
1145          wp_comment_reply( -1, false, 'dashboard', false );
1146          wp_comment_trashnotice();
1147  
1148          echo '</div>';
1149      } else {
1150          return false;
1151      }
1152      return true;
1153  }
1154  
1155  /**
1156   * Display generic dashboard RSS widget feed.
1157   *
1158   * @since 2.5.0
1159   *
1160   * @param string $widget_id
1161   */
1162  function wp_dashboard_rss_output( $widget_id ) {
1163      $widgets = get_option( 'dashboard_widget_options' );
1164      echo '<div class="rss-widget">';
1165      wp_widget_rss_output( $widgets[ $widget_id ] );
1166      echo '</div>';
1167  }
1168  
1169  /**
1170   * Checks to see if all of the feed url in $check_urls are cached.
1171   *
1172   * If $check_urls is empty, look for the rss feed url found in the dashboard
1173   * widget options of $widget_id. If cached, call $callback, a function that
1174   * echoes out output for this widget. If not cache, echo a "Loading..." stub
1175   * which is later replaced by Ajax call (see top of /wp-admin/index.php)
1176   *
1177   * @since 2.5.0
1178   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
1179   *              by adding it to the function signature.
1180   *
1181   * @param string   $widget_id  The widget ID.
1182   * @param callable $callback   The callback function used to display each feed.
1183   * @param array    $check_urls RSS feeds.
1184   * @param mixed    ...$args    Optional additional parameters to pass to the callback function.
1185   * @return bool True on success, false on failure.
1186   */
1187  function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
1188      $doing_ajax = wp_doing_ajax();
1189      $loading    = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p>';
1190      $loading   .= wp_get_admin_notice(
1191          __( 'This widget requires JavaScript.' ),
1192          array(
1193              'type'               => 'error',
1194              'additional_classes' => array( 'inline', 'hide-if-js' ),
1195          )
1196      );
1197  
1198      if ( empty( $check_urls ) ) {
1199          $widgets = get_option( 'dashboard_widget_options' );
1200  
1201          if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
1202              echo $loading;
1203              return false;
1204          }
1205  
1206          $check_urls = array( $widgets[ $widget_id ]['url'] );
1207      }
1208  
1209      $locale    = get_user_locale();
1210      $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
1211      $output    = get_transient( $cache_key );
1212  
1213      if ( false !== $output ) {
1214          echo $output;
1215          return true;
1216      }
1217  
1218      if ( ! $doing_ajax ) {
1219          echo $loading;
1220          return false;
1221      }
1222  
1223      if ( $callback && is_callable( $callback ) ) {
1224          array_unshift( $args, $widget_id, $check_urls );
1225          ob_start();
1226          call_user_func_array( $callback, $args );
1227          // Default lifetime in cache of 12 hours (same as the feeds).
1228          set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );
1229      }
1230  
1231      return true;
1232  }
1233  
1234  //
1235  // Dashboard Widgets Controls.
1236  //
1237  
1238  /**
1239   * Calls widget control callback.
1240   *
1241   * @since 2.5.0
1242   *
1243   * @global callable[] $wp_dashboard_control_callbacks
1244   *
1245   * @param int|false $widget_control_id Optional. Registered widget ID. Default false.
1246   */
1247  function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
1248      global $wp_dashboard_control_callbacks;
1249  
1250      if ( is_scalar( $widget_control_id ) && $widget_control_id
1251          && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] )
1252          && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] )
1253      ) {
1254          call_user_func(
1255              $wp_dashboard_control_callbacks[ $widget_control_id ],
1256              '',
1257              array(
1258                  'id'       => $widget_control_id,
1259                  'callback' => $wp_dashboard_control_callbacks[ $widget_control_id ],
1260              )
1261          );
1262      }
1263  }
1264  
1265  /**
1266   * Sets up the RSS dashboard widget control and $args to be used as input to wp_widget_rss_form().
1267   *
1268   * Handles POST data from RSS-type widgets.
1269   *
1270   * @since 2.5.0
1271   *
1272   * @param string $widget_id
1273   * @param array  $form_inputs
1274   */
1275  function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
1276      $widget_options = get_option( 'dashboard_widget_options' );
1277  
1278      if ( ! $widget_options ) {
1279          $widget_options = array();
1280      }
1281  
1282      if ( ! isset( $widget_options[ $widget_id ] ) ) {
1283          $widget_options[ $widget_id ] = array();
1284      }
1285  
1286      $number = 1; // Hack to use wp_widget_rss_form().
1287  
1288      $widget_options[ $widget_id ]['number'] = $number;
1289  
1290      if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
1291          $_POST['widget-rss'][ $number ]         = wp_unslash( $_POST['widget-rss'][ $number ] );
1292          $widget_options[ $widget_id ]           = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
1293          $widget_options[ $widget_id ]['number'] = $number;
1294  
1295          // Title is optional. If blank, fill it if possible.
1296          if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
1297              $rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
1298              if ( is_wp_error( $rss ) ) {
1299                  $widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
1300              } else {
1301                  $widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
1302                  $rss->__destruct();
1303                  unset( $rss );
1304              }
1305          }
1306  
1307          update_option( 'dashboard_widget_options', $widget_options, false );
1308  
1309          $locale    = get_user_locale();
1310          $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
1311          delete_transient( $cache_key );
1312      }
1313  
1314      wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
1315  }
1316  
1317  
1318  /**
1319   * Renders the Events and News dashboard widget.
1320   *
1321   * @since 4.8.0
1322   */
1323  function wp_dashboard_events_news() {
1324      wp_print_community_events_markup();
1325  
1326      ?>
1327  
1328      <div class="wordpress-news hide-if-no-js">
1329          <?php wp_dashboard_primary(); ?>
1330      </div>
1331  
1332      <p class="community-events-footer">
1333          <?php
1334              printf(
1335                  '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
1336                  'https://make.wordpress.org/community/meetups-landing-page',
1337                  __( 'Meetups' ),
1338                  /* translators: Hidden accessibility text. */
1339                  __( '(opens in a new tab)' )
1340              );
1341          ?>
1342  
1343          |
1344  
1345          <?php
1346              printf(
1347                  '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
1348                  'https://central.wordcamp.org/schedule/',
1349                  __( 'WordCamps' ),
1350                  /* translators: Hidden accessibility text. */
1351                  __( '(opens in a new tab)' )
1352              );
1353          ?>
1354  
1355          |
1356  
1357          <?php
1358              printf(
1359                  '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
1360                  /* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */
1361                  esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ),
1362                  __( 'News' ),
1363                  /* translators: Hidden accessibility text. */
1364                  __( '(opens in a new tab)' )
1365              );
1366          ?>
1367      </p>
1368  
1369      <?php
1370  }
1371  
1372  /**
1373   * Prints the markup for the Community Events section of the Events and News Dashboard widget.
1374   *
1375   * @since 4.8.0
1376   */
1377  function wp_print_community_events_markup() {
1378      $community_events_notice  = '<p class="hide-if-js">' . __( 'The WordPress Events and News feeds require JavaScript.' ) . '</p>';
1379      $community_events_notice .= '<p class="community-events-error-occurred" aria-hidden="true">' . __( 'An error occurred. Please try again.' ) . '</p>';
1380      $community_events_notice .= '<p class="community-events-could-not-locate" aria-hidden="true"></p>';
1381  
1382      wp_admin_notice(
1383          $community_events_notice,
1384          array(
1385              'type'               => 'error',
1386              'additional_classes' => array( 'community-events-errors', 'inline', 'hide-if-js' ),
1387              'paragraph_wrap'     => false,
1388          )
1389      );
1390  
1391      /*
1392       * Hide the main element when the page first loads, because the content
1393       * won't be ready until wp.communityEvents.renderEventsTemplate() has run.
1394       */
1395      ?>
1396      <div id="community-events" class="community-events" aria-hidden="true">
1397          <div class="activity-block">
1398              <p>
1399                  <span id="community-events-location-message"></span>
1400  
1401                  <button class="button-link community-events-toggle-location" aria-expanded="false">
1402                      <span class="dashicons dashicons-location" aria-hidden="true"></span>
1403                      <span class="community-events-location-edit"><?php _e( 'Select location' ); ?></span>
1404                  </button>
1405              </p>
1406  
1407              <form class="community-events-form" aria-hidden="true" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
1408                  <label for="community-events-location">
1409                      <?php _e( 'City:' ); ?>
1410                  </label>
1411                  <?php
1412                  /* translators: Replace with a city related to your locale.
1413                   * Test that it matches the expected location and has upcoming
1414                   * events before including it. If no cities related to your
1415                   * locale have events, then use a city related to your locale
1416                   * that would be recognizable to most users. Use only the city
1417                   * name itself, without any region or country. Use the endonym
1418                   * (native locale name) instead of the English name if possible.
1419                   */
1420                  ?>
1421                  <input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />
1422  
1423                  <?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?>
1424  
1425                  <button class="community-events-cancel button-link" type="button" aria-expanded="false">
1426                      <?php _e( 'Cancel' ); ?>
1427                  </button>
1428  
1429                  <span class="spinner"></span>
1430              </form>
1431          </div>
1432  
1433          <ul class="community-events-results activity-block last"></ul>
1434      </div>
1435  
1436      <?php
1437  }
1438  
1439  /**
1440   * Renders the events templates for the Event and News widget.
1441   *
1442   * @since 4.8.0
1443   */
1444  function wp_print_community_events_templates() {
1445      ?>
1446  
1447      <script id="tmpl-community-events-attend-event-near" type="text/template">
1448          <?php
1449          printf(
1450              /* translators: %s: The name of a city. */
1451              __( 'Attend an upcoming event near %s.' ),
1452              '<strong>{{ data.location.description }}</strong>'
1453          );
1454          ?>
1455      </script>
1456  
1457      <script id="tmpl-community-events-could-not-locate" type="text/template">
1458          <?php
1459          printf(
1460              /* translators: %s is the name of the city we couldn't locate.
1461               * Replace the examples with cities in your locale, but test
1462               * that they match the expected location before including them.
1463               * Use endonyms (native locale names) whenever possible.
1464               */
1465              __( '%s could not be located. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
1466              '<em>{{data.unknownCity}}</em>'
1467          );
1468          ?>
1469      </script>
1470  
1471      <script id="tmpl-community-events-event-list" type="text/template">
1472          <# _.each( data.events, function( event ) { #>
1473              <li class="event event-{{ event.type }} wp-clearfix">
1474                  <div class="event-info">
1475                      <div class="dashicons event-icon" aria-hidden="true"></div>
1476                      <div class="event-info-inner">
1477                          <a class="event-title" href="{{ event.url }}">{{ event.title }}</a>
1478                          <# if ( event.type ) {
1479                              const titleCaseEventType = event.type.replace(
1480                                  /\w\S*/g,
1481                                  function ( type ) { return type.charAt(0).toUpperCase() + type.substr(1).toLowerCase(); }
1482                              );
1483                          #>
1484                              {{ 'wordcamp' === event.type ? 'WordCamp' : titleCaseEventType }}
1485                              <span class="ce-separator" aria-hidden="true"></span>
1486                          <# } #>
1487                          <span class="event-city">{{ event.location.location }}</span>
1488                      </div>
1489                  </div>
1490  
1491                  <div class="event-date-time">
1492                      <span class="event-date">{{ event.user_formatted_date }}</span>
1493                      <# if ( 'meetup' === event.type ) { #>
1494                          <span class="event-time">
1495                              {{ event.user_formatted_time }} {{ event.timeZoneAbbreviation }}
1496                          </span>
1497                      <# } #>
1498                  </div>
1499              </li>
1500          <# } ) #>
1501  
1502          <# if ( data.events.length <= 2 ) { #>
1503              <li class="event-none">
1504                  <?php
1505                  printf(
1506                      /* translators: %s: Localized meetup organization documentation URL. */
1507                      __( 'Want more events? <a href="%s">Help organize the next one</a>!' ),
1508                      __( 'https://make.wordpress.org/community/organize-event-landing-page/' )
1509                  );
1510                  ?>
1511              </li>
1512          <# } #>
1513  
1514      </script>
1515  
1516      <script id="tmpl-community-events-no-upcoming-events" type="text/template">
1517          <li class="event-none">
1518              <# if ( data.location.description ) { #>
1519                  <?php
1520                  printf(
1521                      /* translators: 1: The city the user searched for, 2: Meetup organization documentation URL. */
1522                      __( 'There are no events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize a WordPress event</a>?' ),
1523                      '{{ data.location.description }}',
1524                      __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
1525                  );
1526                  ?>
1527  
1528              <# } else { #>
1529                  <?php
1530                  printf(
1531                      /* translators: %s: Meetup organization documentation URL. */
1532                      __( 'There are no events scheduled near you at the moment. Would you like to <a href="%s">organize a WordPress event</a>?' ),
1533                      __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
1534                  );
1535                  ?>
1536              <# } #>
1537          </li>
1538      </script>
1539      <?php
1540  }
1541  
1542  /**
1543   * 'WordPress Events and News' dashboard widget.
1544   *
1545   * @since 2.7.0
1546   * @since 4.8.0 Removed popular plugins feed.
1547   */
1548  function wp_dashboard_primary() {
1549      $feeds = array(
1550          'news'   => array(
1551  
1552              /**
1553               * Filters the primary link URL for the 'WordPress Events and News' dashboard widget.
1554               *
1555               * @since 2.5.0
1556               *
1557               * @param string $link The widget's primary link URL.
1558               */
1559              'link'         => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ),
1560  
1561              /**
1562               * Filters the primary feed URL for the 'WordPress Events and News' dashboard widget.
1563               *
1564               * @since 2.3.0
1565               *
1566               * @param string $url The widget's primary feed URL.
1567               */
1568              'url'          => apply_filters( 'dashboard_primary_feed', __( 'https://wordpress.org/news/feed/' ) ),
1569  
1570              /**
1571               * Filters the primary link title for the 'WordPress Events and News' dashboard widget.
1572               *
1573               * @since 2.3.0
1574               *
1575               * @param string $title Title attribute for the widget's primary link.
1576               */
1577              'title'        => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
1578              'items'        => 2,
1579              'show_summary' => 0,
1580              'show_author'  => 0,
1581              'show_date'    => 0,
1582          ),
1583          'planet' => array(
1584  
1585              /**
1586               * Filters the secondary link URL for the 'WordPress Events and News' dashboard widget.
1587               *
1588               * @since 2.3.0
1589               *
1590               * @param string $link The widget's secondary link URL.
1591               */
1592              'link'         => apply_filters(
1593                  'dashboard_secondary_link',
1594                  /* translators: Link to the Planet website of the locale. */
1595                  __( 'https://planet.wordpress.org/' )
1596              ),
1597  
1598              /**
1599               * Filters the secondary feed URL for the 'WordPress Events and News' dashboard widget.
1600               *
1601               * @since 2.3.0
1602               *
1603               * @param string $url The widget's secondary feed URL.
1604               */
1605              'url'          => apply_filters(
1606                  'dashboard_secondary_feed',
1607                  /* translators: Link to the Planet feed of the locale. */
1608                  __( 'https://planet.wordpress.org/feed/' )
1609              ),
1610  
1611              /**
1612               * Filters the secondary link title for the 'WordPress Events and News' dashboard widget.
1613               *
1614               * @since 2.3.0
1615               *
1616               * @param string $title Title attribute for the widget's secondary link.
1617               */
1618              'title'        => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
1619  
1620              /**
1621               * Filters the number of secondary link items for the 'WordPress Events and News' dashboard widget.
1622               *
1623               * @since 4.4.0
1624               *
1625               * @param string $items How many items to show in the secondary feed.
1626               */
1627              'items'        => apply_filters( 'dashboard_secondary_items', 3 ),
1628              'show_summary' => 0,
1629              'show_author'  => 0,
1630              'show_date'    => 0,
1631          ),
1632      );
1633  
1634      wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
1635  }
1636  
1637  /**
1638   * Displays the WordPress events and news feeds.
1639   *
1640   * @since 3.8.0
1641   * @since 4.8.0 Removed popular plugins feed.
1642   *
1643   * @param string $widget_id Widget ID.
1644   * @param array  $feeds     Array of RSS feeds.
1645   */
1646  function wp_dashboard_primary_output( $widget_id, $feeds ) {
1647      foreach ( $feeds as $type => $args ) {
1648          $args['type'] = $type;
1649          echo '<div class="rss-widget">';
1650              wp_widget_rss_output( $args['url'], $args );
1651          echo '</div>';
1652      }
1653  }
1654  
1655  /**
1656   * Displays file upload quota on dashboard.
1657   *
1658   * Runs on the {@see 'activity_box_end'} hook in wp_dashboard_right_now().
1659   *
1660   * @since 3.0.0
1661   *
1662   * @return true|null True if not multisite, user can't upload files, or the space check option is disabled.
1663   */
1664  function wp_dashboard_quota() {
1665      if ( ! is_multisite() || ! current_user_can( 'upload_files' )
1666          || get_site_option( 'upload_space_check_disabled' )
1667      ) {
1668          return true;
1669      }
1670  
1671      $quota = get_space_allowed();
1672      $used  = get_space_used();
1673  
1674      if ( $used > $quota ) {
1675          $percentused = '100';
1676      } else {
1677          $percentused = ( $used / $quota ) * 100;
1678      }
1679  
1680      $used_class  = ( $percentused >= 70 ) ? ' warning' : '';
1681      $used        = round( $used, 2 );
1682      $percentused = number_format( $percentused );
1683  
1684      ?>
1685      <h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3>
1686      <div class="mu-storage">
1687      <ul>
1688          <li class="storage-count">
1689              <?php
1690              $text = sprintf(
1691                  /* translators: %s: Number of megabytes. */
1692                  __( '%s MB Space Allowed' ),
1693                  number_format_i18n( $quota )
1694              );
1695              printf(
1696                  '<a href="%1$s">%2$s<span class="screen-reader-text"> (%3$s)</span></a>',
1697                  esc_url( admin_url( 'upload.php' ) ),
1698                  $text,
1699                  /* translators: Hidden accessibility text. */
1700                  __( 'Manage Uploads' )
1701              );
1702              ?>
1703          </li><li class="storage-count <?php echo $used_class; ?>">
1704              <?php
1705              $text = sprintf(
1706                  /* translators: 1: Number of megabytes, 2: Percentage. */
1707                  __( '%1$s MB (%2$s%%) Space Used' ),
1708                  number_format_i18n( $used, 2 ),
1709                  $percentused
1710              );
1711              printf(
1712                  '<a href="%1$s" class="musublink">%2$s<span class="screen-reader-text"> (%3$s)</span></a>',
1713                  esc_url( admin_url( 'upload.php' ) ),
1714                  $text,
1715                  /* translators: Hidden accessibility text. */
1716                  __( 'Manage Uploads' )
1717              );
1718              ?>
1719          </li>
1720      </ul>
1721      </div>
1722      <?php
1723      return null;
1724  }
1725  
1726  /**
1727   * Displays the browser update nag.
1728   *
1729   * @since 3.2.0
1730   * @since 5.8.0 Added a special message for Internet Explorer users.
1731   *
1732   * @global bool $is_IE
1733   */
1734  function wp_dashboard_browser_nag() {
1735      global $is_IE;
1736  
1737      $notice   = '';
1738      $response = wp_check_browser_version();
1739  
1740      if ( $response ) {
1741          if ( $is_IE ) {
1742              $msg = __( 'Internet Explorer does not give you the best WordPress experience. Switch to Microsoft Edge, or another more modern browser to get the most from your site.' );
1743          } elseif ( $response['insecure'] ) {
1744              $msg = sprintf(
1745                  /* translators: %s: Browser name and link. */
1746                  __( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ),
1747                  sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
1748              );
1749          } else {
1750              $msg = sprintf(
1751                  /* translators: %s: Browser name and link. */
1752                  __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ),
1753                  sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
1754              );
1755          }
1756  
1757          $browser_nag_class = '';
1758          if ( ! empty( $response['img_src'] ) ) {
1759              $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) ) ? $response['img_src_ssl'] : $response['img_src'];
1760  
1761              $notice           .= '<div class="alignright browser-icon"><img src="' . esc_url( $img_src ) . '" alt="" /></div>';
1762              $browser_nag_class = ' has-browser-icon';
1763          }
1764          $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
1765  
1766          $browsehappy = 'https://browsehappy.com/';
1767          $locale      = get_user_locale();
1768          if ( 'en_US' !== $locale ) {
1769              $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
1770          }
1771  
1772          if ( $is_IE ) {
1773              $msg_browsehappy = sprintf(
1774                  /* translators: %s: Browse Happy URL. */
1775                  __( 'Learn how to <a href="%s" class="update-browser-link">browse happy</a>' ),
1776                  esc_url( $browsehappy )
1777              );
1778          } else {
1779              $msg_browsehappy = sprintf(
1780                  /* translators: 1: Browser update URL, 2: Browser name, 3: Browse Happy URL. */
1781                  __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ),
1782                  esc_attr( $response['update_url'] ),
1783                  esc_html( $response['name'] ),
1784                  esc_url( $browsehappy )
1785              );
1786          }
1787  
1788          $notice .= '<p>' . $msg_browsehappy . '</p>';
1789          $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss" aria-label="' . esc_attr__( 'Dismiss the browser warning panel' ) . '">' . __( 'Dismiss' ) . '</a></p>';
1790          $notice .= '<div class="clear"></div>';
1791      }
1792  
1793      /**
1794       * Filters the notice output for the 'Browse Happy' nag meta box.
1795       *
1796       * @since 3.2.0
1797       *
1798       * @param string      $notice   The notice content.
1799       * @param array|false $response An array containing web browser information, or
1800       *                              false on failure. See wp_check_browser_version().
1801       */
1802      echo apply_filters( 'browse-happy-notice', $notice, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1803  }
1804  
1805  /**
1806   * Adds an additional class to the browser nag if the current version is insecure.
1807   *
1808   * @since 3.2.0
1809   *
1810   * @param string[] $classes Array of meta box classes.
1811   * @return string[] Modified array of meta box classes.
1812   */
1813  function dashboard_browser_nag_class( $classes ) {
1814      $response = wp_check_browser_version();
1815  
1816      if ( $response && $response['insecure'] ) {
1817          $classes[] = 'browser-insecure';
1818      }
1819  
1820      return $classes;
1821  }
1822  
1823  /**
1824   * Checks if the user needs a browser update.
1825   *
1826   * @since 3.2.0
1827   *
1828   * @return array|false Array of browser data on success, false on failure.
1829   */
1830  function wp_check_browser_version() {
1831      if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
1832          return false;
1833      }
1834  
1835      $key = md5( $_SERVER['HTTP_USER_AGENT'] );
1836  
1837      $response = get_site_transient( 'browser_' . $key );
1838  
1839      if ( false === $response ) {
1840          $url     = 'http://api.wordpress.org/core/browse-happy/1.1/';
1841          $options = array(
1842              'body'       => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
1843              'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
1844          );
1845  
1846          if ( wp_http_supports( array( 'ssl' ) ) ) {
1847              $url = set_url_scheme( $url, 'https' );
1848          }
1849  
1850          $response = wp_remote_post( $url, $options );
1851  
1852          if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
1853              return false;
1854          }
1855  
1856          /**
1857           * Response should be an array with:
1858           *  'platform' - string - A user-friendly platform name, if it can be determined
1859           *  'name' - string - A user-friendly browser name
1860           *  'version' - string - The version of the browser the user is using
1861           *  'current_version' - string - The most recent version of the browser
1862           *  'upgrade' - boolean - Whether the browser needs an upgrade
1863           *  'insecure' - boolean - Whether the browser is deemed insecure
1864           *  'update_url' - string - The url to visit to upgrade
1865           *  'img_src' - string - An image representing the browser
1866           *  'img_src_ssl' - string - An image (over SSL) representing the browser
1867           */
1868          $response = json_decode( wp_remote_retrieve_body( $response ), true );
1869  
1870          if ( ! is_array( $response ) ) {
1871              return false;
1872          }
1873  
1874          set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
1875      }
1876  
1877      return $response;
1878  }
1879  
1880  /**
1881   * Displays the PHP update nag.
1882   *
1883   * @since 5.1.0
1884   */
1885  function wp_dashboard_php_nag() {
1886      $response = wp_check_php_version();
1887  
1888      if ( ! $response ) {
1889          return;
1890      }
1891  
1892      if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
1893          // The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates.
1894  
1895          if ( $response['is_lower_than_future_minimum'] ) {
1896              $message = sprintf(
1897                  /* translators: %s: The server PHP version. */
1898                  __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates and soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ),
1899                  PHP_VERSION
1900              );
1901          } else {
1902              $message = sprintf(
1903                  /* translators: %s: The server PHP version. */
1904                  __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates. It should be updated.' ),
1905                  PHP_VERSION
1906              );
1907          }
1908      } elseif ( $response['is_lower_than_future_minimum'] ) {
1909          $message = sprintf(
1910              /* translators: %s: The server PHP version. */
1911              __( 'Your site is running on an outdated version of PHP (%s), which soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ),
1912              PHP_VERSION
1913          );
1914      } else {
1915          $message = sprintf(
1916              /* translators: %s: The server PHP version. */
1917              __( 'Your site is running on an outdated version of PHP (%s), which should be updated.' ),
1918              PHP_VERSION
1919          );
1920      }
1921      ?>
1922      <p class="bigger-bolder-text"><?php echo $message; ?></p>
1923  
1924      <p><?php _e( 'What is PHP and how does it affect my site?' ); ?></p>
1925      <p>
1926          <?php _e( 'PHP is one of the programming languages used to build WordPress. Newer versions of PHP receive regular security updates and may increase your site&#8217;s performance.' ); ?>
1927          <?php
1928          if ( ! empty( $response['recommended_version'] ) ) {
1929              printf(
1930                  /* translators: %s: The minimum recommended PHP version. */
1931                  __( 'The minimum recommended version of PHP is %s.' ),
1932                  $response['recommended_version']
1933              );
1934          }
1935          ?>
1936      </p>
1937  
1938      <p class="button-container">
1939          <?php
1940          printf(
1941              '<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
1942              esc_url( wp_get_update_php_url() ),
1943              __( 'Learn more about updating PHP' ),
1944              /* translators: Hidden accessibility text. */
1945              __( '(opens in a new tab)' )
1946          );
1947          ?>
1948      </p>
1949      <?php
1950  
1951      wp_update_php_annotation();
1952      wp_direct_php_update_button();
1953  }
1954  
1955  /**
1956   * Adds an additional class to the PHP nag if the current version is insecure.
1957   *
1958   * @since 5.1.0
1959   *
1960   * @param string[] $classes Array of meta box classes.
1961   * @return string[] Modified array of meta box classes.
1962   */
1963  function dashboard_php_nag_class( $classes ) {
1964      $response = wp_check_php_version();
1965  
1966      if ( ! $response ) {
1967          return $classes;
1968      }
1969  
1970      if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
1971          $classes[] = 'php-no-security-updates';
1972      } elseif ( $response['is_lower_than_future_minimum'] ) {
1973          $classes[] = 'php-version-lower-than-future-minimum';
1974      }
1975  
1976      return $classes;
1977  }
1978  
1979  /**
1980   * Displays the Site Health Status widget.
1981   *
1982   * @since 5.4.0
1983   */
1984  function wp_dashboard_site_health() {
1985      $get_issues = get_transient( 'health-check-site-status-result' );
1986  
1987      $issue_counts = array();
1988  
1989      if ( false !== $get_issues ) {
1990          $issue_counts = json_decode( $get_issues, true );
1991      }
1992  
1993      if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
1994          $issue_counts = array(
1995              'good'        => 0,
1996              'recommended' => 0,
1997              'critical'    => 0,
1998          );
1999      }
2000  
2001      $issues_total = $issue_counts['recommended'] + $issue_counts['critical'];
2002      ?>
2003      <div class="health-check-widget">
2004          <div class="health-check-widget-title-section site-health-progress-wrapper loading">
2005              <div class="site-health-progress">
2006                  <svg aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg">
2007                      <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
2008                      <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
2009                  </svg>
2010              </div>
2011              <div class="site-health-progress-label">
2012                  <?php if ( false === $get_issues ) : ?>
2013                      <?php _e( 'No information yet&hellip;' ); ?>
2014                  <?php else : ?>
2015                      <?php _e( 'Results are still loading&hellip;' ); ?>
2016                  <?php endif; ?>
2017              </div>
2018          </div>
2019  
2020          <div class="site-health-details">
2021              <?php if ( false === $get_issues ) : ?>
2022                  <p>
2023                      <?php
2024                      printf(
2025                          /* translators: %s: URL to Site Health screen. */
2026                          __( 'Site health checks will automatically run periodically to gather information about your site. You can also <a href="%s">visit the Site Health screen</a> to gather information about your site now.' ),
2027                          esc_url( admin_url( 'site-health.php' ) )
2028                      );
2029                      ?>
2030                  </p>
2031              <?php else : ?>
2032                  <p>
2033                      <?php if ( $issues_total <= 0 ) : ?>
2034                          <?php _e( 'Great job! Your site currently passes all site health checks.' ); ?>
2035                      <?php elseif ( 1 === (int) $issue_counts['critical'] ) : ?>
2036                          <?php _e( 'Your site has a critical issue that should be addressed as soon as possible to improve its performance and security.' ); ?>
2037                      <?php elseif ( $issue_counts['critical'] > 1 ) : ?>
2038                          <?php _e( 'Your site has critical issues that should be addressed as soon as possible to improve its performance and security.' ); ?>
2039                      <?php elseif ( 1 === (int) $issue_counts['recommended'] ) : ?>
2040                          <?php _e( 'Your site&#8217;s health is looking good, but there is still one thing you can do to improve its performance and security.' ); ?>
2041                      <?php else : ?>
2042                          <?php _e( 'Your site&#8217;s health is looking good, but there are still some things you can do to improve its performance and security.' ); ?>
2043                      <?php endif; ?>
2044                  </p>
2045              <?php endif; ?>
2046  
2047              <?php if ( $issues_total > 0 && false !== $get_issues ) : ?>
2048                  <p>
2049                      <?php
2050                      printf(
2051                          /* translators: 1: Number of issues. 2: URL to Site Health screen. */
2052                          _n(
2053                              'Take a look at the <strong>%1$d item</strong> on the <a href="%2$s">Site Health screen</a>.',
2054                              'Take a look at the <strong>%1$d items</strong> on the <a href="%2$s">Site Health screen</a>.',
2055                              $issues_total
2056                          ),
2057                          $issues_total,
2058                          esc_url( admin_url( 'site-health.php' ) )
2059                      );
2060                      ?>
2061                  </p>
2062              <?php endif; ?>
2063          </div>
2064      </div>
2065  
2066      <?php
2067  }
2068  
2069  /**
2070   * Outputs empty dashboard widget to be populated by JS later.
2071   *
2072   * Usable by plugins.
2073   *
2074   * @since 2.5.0
2075   */
2076  function wp_dashboard_empty() {}
2077  
2078  /**
2079   * Displays a welcome panel to introduce users to WordPress.
2080   *
2081   * @since 3.3.0
2082   * @since 5.9.0 Send users to the Site Editor if the active theme is block-based.
2083   */
2084  function wp_welcome_panel() {
2085      list( $display_version ) = explode( '-', wp_get_wp_version() );
2086      $can_customize           = current_user_can( 'customize' );
2087      $is_block_theme          = wp_is_block_theme();
2088      ?>
2089      <div class="welcome-panel-content">
2090      <div class="welcome-panel-header-wrap">
2091          <div class="welcome-panel-header">
2092              <div class="welcome-panel-header-image">
2093                  <?php echo file_get_contents( dirname( __DIR__ ) . '/images/dashboard-background.svg' ); ?>
2094              </div>
2095              <h2><?php _e( 'Welcome to WordPress!' ); ?></h2>
2096              <p>
2097                  <a href="<?php echo esc_url( admin_url( 'about.php' ) ); ?>">
2098                  <?php
2099                      /* translators: %s: Current WordPress version. */
2100                      printf( __( 'Learn more about the %s version.' ), esc_html( $display_version ) );
2101                  ?>
2102                  </a>
2103              </p>
2104          </div>
2105      </div>
2106      <div class="welcome-panel-column-container">
2107          <div class="welcome-panel-column">
2108              <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
2109                  <rect width="48" height="48" rx="4" fill="#1E1E1E"/>
2110                  <path fill-rule="evenodd" clip-rule="evenodd" d="M32.0668 17.0854L28.8221 13.9454L18.2008 24.671L16.8983 29.0827L21.4257 27.8309L32.0668 17.0854ZM16 32.75H24V31.25H16V32.75Z" fill="white"/>
2111              </svg>
2112              <div class="welcome-panel-column-content">
2113                  <h3><?php _e( 'Author rich content with blocks and patterns' ); ?></h3>
2114                  <p><?php _e( 'Block patterns are pre-configured block layouts. Use them to get inspired or create new pages in a flash.' ); ?></p>
2115                  <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page' ) ); ?>"><?php _e( 'Add a new page' ); ?></a>
2116              </div>
2117          </div>
2118          <div class="welcome-panel-column">
2119              <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
2120                  <rect width="48" height="48" rx="4" fill="#1E1E1E"/>
2121                  <path fill-rule="evenodd" clip-rule="evenodd" d="M18 16h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H18a2 2 0 0 1-2-2V18a2 2 0 0 1 2-2zm12 1.5H18a.5.5 0 0 0-.5.5v3h13v-3a.5.5 0 0 0-.5-.5zm.5 5H22v8h8a.5.5 0 0 0 .5-.5v-7.5zm-10 0h-3V30a.5.5 0 0 0 .5.5h2.5v-8z" fill="#fff"/>
2122              </svg>
2123              <div class="welcome-panel-column-content">
2124              <?php if ( $is_block_theme ) : ?>
2125                  <h3><?php _e( 'Customize your entire site with block themes' ); ?></h3>
2126                  <p><?php _e( 'Design everything on your site &#8212; from the header down to the footer, all using blocks and patterns.' ); ?></p>
2127                  <a href="<?php echo esc_url( admin_url( 'site-editor.php' ) ); ?>"><?php _e( 'Open site editor' ); ?></a>
2128              <?php else : ?>
2129                  <h3><?php _e( 'Start Customizing' ); ?></h3>
2130                  <p><?php _e( 'Configure your site&#8217;s logo, header, menus, and more in the Customizer.' ); ?></p>
2131                  <?php if ( $can_customize ) : ?>
2132                      <a class="load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Open the Customizer' ); ?></a>
2133                  <?php endif; ?>
2134              <?php endif; ?>
2135              </div>
2136          </div>
2137          <div class="welcome-panel-column">
2138              <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
2139                  <rect width="48" height="48" rx="4" fill="#1E1E1E"/>
2140                  <path fill-rule="evenodd" clip-rule="evenodd" d="M31 24a7 7 0 0 1-7 7V17a7 7 0 0 1 7 7zm-7-8a8 8 0 1 1 0 16 8 8 0 0 1 0-16z" fill="#fff"/>
2141              </svg>
2142              <div class="welcome-panel-column-content">
2143              <?php if ( $is_block_theme ) : ?>
2144                  <h3><?php _e( 'Switch up your site&#8217;s look & feel with Styles' ); ?></h3>
2145                  <p><?php _e( 'Tweak your site, or give it a whole new look! Get creative &#8212; how about a new color palette or font?' ); ?></p>
2146                  <a href="<?php echo esc_url( add_query_arg( 'p', rawurlencode( '/styles' ), admin_url( 'site-editor.php' ) ) ); ?>"><?php _e( 'Edit styles' ); ?></a>
2147              <?php else : ?>
2148                  <h3><?php _e( 'Discover a new way to build your site.' ); ?></h3>
2149                  <p><?php _e( 'There is a new kind of WordPress theme, called a block theme, that lets you build the site you&#8217;ve always wanted &#8212; with blocks and styles.' ); ?></p>
2150                  <a href="<?php echo esc_url( __( 'https://wordpress.org/documentation/article/block-themes/' ) ); ?>"><?php _e( 'Learn about block themes' ); ?></a>
2151              <?php endif; ?>
2152              </div>
2153          </div>
2154      </div>
2155      </div>
2156      <?php
2157  }


Generated : Sat Sep 5 08:20:28 2026 Cross-referenced by PHPXref