[ 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   *
 545   * @global int $post_ID
 546   *
 547   * @param string|false $error_msg Optional. Error message. Default false.
 548   */
 549  function wp_dashboard_quick_press( $error_msg = false ) {
 550      global $post_ID;
 551  
 552      if ( ! current_user_can( 'edit_posts' ) ) {
 553          return;
 554      }
 555  
 556      // Check if a new auto-draft (= no new post_ID) is needed or if the old can be used.
 557      $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID.
 558  
 559      if ( $last_post_id ) {
 560          $post = get_post( $last_post_id );
 561  
 562          if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore.
 563              $post = get_default_post_to_edit( 'post', true );
 564              update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
 565          } else {
 566              $post->post_title = ''; // Remove the auto draft title.
 567          }
 568      } else {
 569          $post    = get_default_post_to_edit( 'post', true );
 570          $user_id = get_current_user_id();
 571  
 572          // Don't create an option if this is a super admin who does not belong to this site.
 573          if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
 574              update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
 575          }
 576      }
 577  
 578      $post_ID = (int) $post->ID;
 579      ?>
 580  
 581      <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
 582  
 583          <?php
 584          if ( $error_msg ) {
 585              wp_admin_notice(
 586                  $error_msg,
 587                  array(
 588                      'additional_classes' => array( 'error' ),
 589                  )
 590              );
 591          }
 592          ?>
 593  
 594          <div class="input-text-wrap" id="title-wrap">
 595              <label for="title">
 596                  <?php
 597                  /** This filter is documented in wp-admin/edit-form-advanced.php */
 598                  echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
 599                  ?>
 600              </label>
 601              <input type="text" name="post_title" id="title" autocomplete="off" />
 602          </div>
 603  
 604          <div class="textarea-wrap" id="description-wrap">
 605              <label for="content"><?php _e( 'Content' ); ?></label>
 606              <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>
 607          </div>
 608  
 609          <p class="submit">
 610              <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
 611              <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
 612              <input type="hidden" name="post_type" value="post" />
 613              <?php wp_nonce_field( 'add-post' ); ?>
 614              <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
 615              <br class="clear" />
 616          </p>
 617  
 618      </form>
 619      <?php
 620      wp_dashboard_recent_drafts();
 621  }
 622  
 623  /**
 624   * Show recent drafts of the user on the dashboard.
 625   *
 626   * @since 2.7.0
 627   *
 628   * @param WP_Post[]|false $drafts Optional. Array of posts to display. Default false.
 629   */
 630  function wp_dashboard_recent_drafts( $drafts = false ) {
 631      if ( ! $drafts ) {
 632          $query_args = array(
 633              'post_type'      => 'post',
 634              'post_status'    => 'draft',
 635              'author'         => get_current_user_id(),
 636              'posts_per_page' => 4,
 637              'orderby'        => 'modified',
 638              'order'          => 'DESC',
 639          );
 640  
 641          /**
 642           * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
 643           *
 644           * @since 4.4.0
 645           *
 646           * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
 647           */
 648          $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );
 649  
 650          $drafts = get_posts( $query_args );
 651          if ( ! $drafts ) {
 652              return;
 653          }
 654      }
 655  
 656      echo '<div class="drafts">';
 657  
 658      if ( count( $drafts ) > 3 ) {
 659          printf(
 660              '<p class="view-all"><a href="%s">%s</a></p>' . "\n",
 661              esc_url( admin_url( 'edit.php?post_status=draft' ) ),
 662              __( 'View all drafts' )
 663          );
 664      }
 665  
 666      echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n";
 667      echo '<ul>';
 668  
 669      /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
 670      $draft_length = (int) _x( '10', 'draft_length' );
 671  
 672      $drafts = array_slice( $drafts, 0, 3 );
 673      foreach ( $drafts as $draft ) {
 674          $url   = get_edit_post_link( $draft->ID );
 675          $title = _draft_or_post_title( $draft->ID );
 676  
 677          echo "<li>\n";
 678          printf(
 679              '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
 680              esc_url( $url ),
 681              /* translators: %s: Post title. */
 682              esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
 683              esc_html( $title ),
 684              get_the_time( 'c', $draft ),
 685              get_the_time( __( 'F j, Y' ), $draft )
 686          );
 687  
 688          $the_content = wp_trim_words( $draft->post_content, $draft_length );
 689  
 690          if ( $the_content ) {
 691              echo '<p>' . $the_content . '</p>';
 692          }
 693          echo "</li>\n";
 694      }
 695  
 696      echo "</ul>\n";
 697      echo '</div>';
 698  }
 699  
 700  /**
 701   * Outputs a row for the Recent Comments widget.
 702   *
 703   * @access private
 704   * @since 2.7.0
 705   *
 706   * @global WP_Comment $comment Global comment object.
 707   *
 708   * @param WP_Comment $comment   The current comment.
 709   * @param bool       $show_date Optional. Whether to display the date.
 710   */
 711  function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
 712      $GLOBALS['comment'] = clone $comment;
 713  
 714      if ( $comment->comment_post_ID > 0 ) {
 715          $comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
 716          $comment_post_url   = get_the_permalink( $comment->comment_post_ID );
 717          $comment_post_link  = '<a href="' . esc_url( $comment_post_url ) . '">' . $comment_post_title . '</a>';
 718      } else {
 719          $comment_post_link = '';
 720      }
 721  
 722      $actions_string = '';
 723      if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
 724          // Pre-order it: Approve | Reply | Edit | Spam | Trash.
 725          $actions = array(
 726              'approve'   => '',
 727              'unapprove' => '',
 728              'reply'     => '',
 729              'edit'      => '',
 730              'spam'      => '',
 731              'trash'     => '',
 732              'delete'    => '',
 733              'view'      => '',
 734          );
 735  
 736          $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'approve-comment_' . $comment->comment_ID ) );
 737          $del_nonce     = esc_html( '_wpnonce=' . wp_create_nonce( 'delete-comment_' . $comment->comment_ID ) );
 738  
 739          $action_string = 'comment.php?action=%s&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . '&%s';
 740  
 741          $approve_url   = sprintf( $action_string, 'approvecomment', $approve_nonce );
 742          $unapprove_url = sprintf( $action_string, 'unapprovecomment', $approve_nonce );
 743          $spam_url      = sprintf( $action_string, 'spamcomment', $del_nonce );
 744          $trash_url     = sprintf( $action_string, 'trashcomment', $del_nonce );
 745          $delete_url    = sprintf( $action_string, 'deletecomment', $del_nonce );
 746  
 747          $actions['approve'] = sprintf(
 748              '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
 749              esc_url( $approve_url ),
 750              "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
 751              esc_attr__( 'Approve this comment' ),
 752              __( 'Approve' )
 753          );
 754  
 755          $actions['unapprove'] = sprintf(
 756              '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
 757              esc_url( $unapprove_url ),
 758              "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
 759              esc_attr__( 'Unapprove this comment' ),
 760              __( 'Unapprove' )
 761          );
 762  
 763          $actions['edit'] = sprintf(
 764              '<a href="%s" aria-label="%s">%s</a>',
 765              "comment.php?action=editcomment&amp;c={$comment->comment_ID}",
 766              esc_attr__( 'Edit this comment' ),
 767              __( 'Edit' )
 768          );
 769  
 770          $actions['reply'] = sprintf(
 771              '<button type="button" onclick="window.commentReply && commentReply.open(\'%s\',\'%s\');" class="vim-r button-link hide-if-no-js" aria-label="%s">%s</button>',
 772              $comment->comment_ID,
 773              $comment->comment_post_ID,
 774              esc_attr__( 'Reply to this comment' ),
 775              /* translators: Comment reply button text. */
 776              _x( 'Reply', 'verb' )
 777          );
 778  
 779          $actions['spam'] = sprintf(
 780              '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 781              esc_url( $spam_url ),
 782              "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
 783              esc_attr__( 'Mark this comment as spam' ),
 784              /* translators: "Mark as spam" link. */
 785              _x( 'Spam', 'verb' )
 786          );
 787  
 788          if ( ! EMPTY_TRASH_DAYS ) {
 789              $actions['delete'] = sprintf(
 790                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 791                  esc_url( $delete_url ),
 792                  "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
 793                  esc_attr__( 'Delete this comment permanently' ),
 794                  __( 'Delete Permanently' )
 795              );
 796          } else {
 797              $actions['trash'] = sprintf(
 798                  '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
 799                  esc_url( $trash_url ),
 800                  "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
 801                  esc_attr__( 'Move this comment to the Trash' ),
 802                  _x( 'Trash', 'verb' )
 803              );
 804          }
 805  
 806          $actions['view'] = sprintf(
 807              '<a class="comment-link" href="%s" aria-label="%s">%s</a>',
 808              esc_url( get_comment_link( $comment ) ),
 809              esc_attr__( 'View this comment' ),
 810              __( 'View' )
 811          );
 812  
 813          /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */
 814          $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
 815  
 816          $i = 0;
 817  
 818          foreach ( $actions as $action => $link ) {
 819              ++$i;
 820  
 821              if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i )
 822                  || 1 === $i
 823              ) {
 824                  $separator = '';
 825              } else {
 826                  $separator = ' | ';
 827              }
 828  
 829              // Reply and quickedit need a hide-if-no-js span.
 830              if ( 'reply' === $action || 'quickedit' === $action ) {
 831                  $action .= ' hide-if-no-js';
 832              }
 833  
 834              if ( 'view' === $action && '1' !== $comment->comment_approved ) {
 835                  $action .= ' hidden';
 836              }
 837  
 838              $actions_string .= "<span class='$action'>{$separator}{$link}</span>";
 839          }
 840      }
 841      ?>
 842  
 843          <li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>
 844  
 845              <?php
 846              $comment_row_class = '';
 847  
 848              if ( get_option( 'show_avatars' ) ) {
 849                  echo get_avatar( $comment, 50, 'mystery' );
 850                  $comment_row_class .= ' has-avatar';
 851              }
 852              ?>
 853  
 854              <?php if ( ! $comment->comment_type || 'comment' === $comment->comment_type ) : ?>
 855  
 856              <div class="dashboard-comment-wrap has-row-actions <?php echo $comment_row_class; ?>">
 857              <p class="comment-meta">
 858                  <?php
 859                  // Comments might not have a post they relate to, e.g. programmatically created ones.
 860                  if ( $comment_post_link ) {
 861                      printf(
 862                          /* translators: 1: Comment author, 2: Post link, 3: Notification if the comment is pending. */
 863                          __( 'From %1$s on %2$s %3$s' ),
 864                          '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
 865                          $comment_post_link,
 866                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 867                      );
 868                  } else {
 869                      printf(
 870                          /* translators: 1: Comment author, 2: Notification if the comment is pending. */
 871                          __( 'From %1$s %2$s' ),
 872                          '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
 873                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 874                      );
 875                  }
 876                  ?>
 877              </p>
 878  
 879                  <?php
 880              else :
 881                  switch ( $comment->comment_type ) {
 882                      case 'pingback':
 883                          $type = __( 'Pingback' );
 884                          break;
 885                      case 'trackback':
 886                          $type = __( 'Trackback' );
 887                          break;
 888                      default:
 889                          $type = ucwords( $comment->comment_type );
 890                  }
 891                  $type = esc_html( $type );
 892                  ?>
 893              <div class="dashboard-comment-wrap has-row-actions">
 894              <p class="comment-meta">
 895                  <?php
 896                  // Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
 897                  if ( $comment_post_link ) {
 898                      printf(
 899                          /* translators: 1: Type of comment, 2: Post link, 3: Notification if the comment is pending. */
 900                          _x( '%1$s on %2$s %3$s', 'dashboard' ),
 901                          "<strong>$type</strong>",
 902                          $comment_post_link,
 903                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 904                      );
 905                  } else {
 906                      printf(
 907                          /* translators: 1: Type of comment, 2: Notification if the comment is pending. */
 908                          _x( '%1$s %2$s', 'dashboard' ),
 909                          "<strong>$type</strong>",
 910                          '<span class="approve">' . __( '[Pending]' ) . '</span>'
 911                      );
 912                  }
 913                  ?>
 914              </p>
 915              <p class="comment-author"><?php comment_author_link( $comment ); ?></p>
 916  
 917              <?php endif; // comment_type ?>
 918              <blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote>
 919              <?php if ( $actions_string ) : ?>
 920              <p class="row-actions"><?php echo $actions_string; ?></p>
 921              <?php endif; ?>
 922              </div>
 923          </li>
 924      <?php
 925      $GLOBALS['comment'] = null;
 926  }
 927  
 928  /**
 929   * Outputs the Activity widget.
 930   *
 931   * Callback function for {@see 'dashboard_activity'}.
 932   *
 933   * @since 3.8.0
 934   */
 935  function wp_dashboard_site_activity() {
 936  
 937      echo '<div id="activity-widget">';
 938  
 939      $future_posts = wp_dashboard_recent_posts(
 940          array(
 941              'max'    => 5,
 942              'status' => 'future',
 943              'order'  => 'ASC',
 944              'title'  => __( 'Publishing Soon' ),
 945              'id'     => 'future-posts',
 946          )
 947      );
 948      $recent_posts = wp_dashboard_recent_posts(
 949          array(
 950              'max'    => 5,
 951              'status' => 'publish',
 952              'order'  => 'DESC',
 953              'title'  => __( 'Recently Published' ),
 954              'id'     => 'published-posts',
 955          )
 956      );
 957  
 958      $recent_comments = wp_dashboard_recent_comments();
 959  
 960      if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
 961          echo '<div class="no-activity">';
 962          echo '<p>' . __( 'No activity yet!' ) . '</p>';
 963          echo '</div>';
 964      }
 965  
 966      echo '</div>';
 967  }
 968  
 969  /**
 970   * Generates Publishing Soon and Recently Published sections.
 971   *
 972   * @since 3.8.0
 973   *
 974   * @param array $args {
 975   *     An array of query and display arguments.
 976   *
 977   *     @type int    $max     Number of posts to display.
 978   *     @type string $status  Post status.
 979   *     @type string $order   Designates ascending ('ASC') or descending ('DESC') order.
 980   *     @type string $title   Section title.
 981   *     @type string $id      The container id.
 982   * }
 983   * @return bool False if no posts were found. True otherwise.
 984   */
 985  function wp_dashboard_recent_posts( $args ) {
 986      $query_args = array(
 987          'post_type'      => 'post',
 988          'post_status'    => $args['status'],
 989          'orderby'        => 'date',
 990          'order'          => $args['order'],
 991          'posts_per_page' => (int) $args['max'],
 992          'no_found_rows'  => true,
 993          'cache_results'  => true,
 994          'perm'           => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
 995      );
 996  
 997      /**
 998       * Filters the query arguments used for the Recent Posts widget.
 999       *
1000       * @since 4.2.0
1001       *
1002       * @param array $query_args The arguments passed to WP_Query to produce the list of posts.
1003       */
1004      $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args );
1005  
1006      $posts = new WP_Query( $query_args );
1007  
1008      if ( $posts->have_posts() ) {
1009  
1010          echo '<div id="' . $args['id'] . '" class="activity-block">';
1011  
1012          echo '<h3>' . $args['title'] . '</h3>';
1013  
1014          echo '<ul>';
1015  
1016          $today    = current_time( 'Y-m-d' );
1017          $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
1018          $year     = current_time( 'Y' );
1019  
1020          while ( $posts->have_posts() ) {
1021              $posts->the_post();
1022  
1023              $time = get_the_time( 'U' );
1024  
1025              if ( ! is_int( $time ) ) {
1026                  /* 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 */
1027                  $date = get_the_date( __( 'M jS Y' ) );
1028              } elseif ( gmdate( 'Y-m-d', $time ) === $today ) {
1029                  $date = __( 'Today' );
1030              } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) {
1031                  $date = __( 'Tomorrow' );
1032              } elseif ( gmdate( 'Y', $time ) !== $year ) {
1033                  /* 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 */
1034                  $date = date_i18n( __( 'M jS Y' ), $time );
1035              } else {
1036                  /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/manual/datetime.format.php */
1037                  $date = date_i18n( __( 'M jS' ), $time );
1038              }
1039  
1040              // Use the post edit link for those who can edit, the permalink otherwise.
1041              $recent_post_link = current_user_can( 'edit_post', get_the_ID() ) ? get_edit_post_link() : get_permalink();
1042  
1043              $draft_or_post_title = _draft_or_post_title();
1044              printf(
1045                  '<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
1046                  /* translators: 1: Relative date, 2: Time. */
1047                  sprintf( _x( '%1$s, %2$s', 'dashboard' ), $date, get_the_time() ),
1048                  $recent_post_link,
1049                  /* translators: %s: Post title. */
1050                  esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $draft_or_post_title ) ),
1051                  $draft_or_post_title
1052              );
1053          }
1054  
1055          echo '</ul>';
1056          echo '</div>';
1057  
1058      } else {
1059          return false;
1060      }
1061  
1062      wp_reset_postdata();
1063  
1064      return true;
1065  }
1066  
1067  /**
1068   * Show Comments section.
1069   *
1070   * @since 3.8.0
1071   *
1072   * @param int $total_items Optional. Number of comments to query. Default 5.
1073   * @return bool False if no comments were found. True otherwise.
1074   */
1075  function wp_dashboard_recent_comments( $total_items = 5 ) {
1076      // Select all comment types and filter out spam later for better query performance.
1077      $comments = array();
1078  
1079      $comments_query = array(
1080          'number' => $total_items * 5,
1081          'offset' => 0,
1082      );
1083  
1084      if ( ! current_user_can( 'edit_posts' ) ) {
1085          $comments_query['status'] = 'approve';
1086      }
1087  
1088      $comments_count = 0;
1089      do {
1090          $possible = get_comments( $comments_query );
1091  
1092          if ( empty( $possible ) || ! is_array( $possible ) ) {
1093              break;
1094          }
1095  
1096          foreach ( $possible as $comment ) {
1097              if ( ! current_user_can( 'edit_post', $comment->comment_post_ID )
1098                  && ( post_password_required( $comment->comment_post_ID )
1099                      || ! current_user_can( 'read_post', $comment->comment_post_ID ) )
1100              ) {
1101                  // The user has no access to the post and thus cannot see the comments.
1102                  continue;
1103              }
1104  
1105              $comments[]     = $comment;
1106              $comments_count = count( $comments );
1107  
1108              if ( $comments_count === $total_items ) {
1109                  break 2;
1110              }
1111          }
1112  
1113          $comments_query['offset'] += $comments_query['number'];
1114          $comments_query['number']  = $total_items * 10;
1115      } while ( $comments_count < $total_items );
1116  
1117      if ( $comments ) {
1118          echo '<div id="latest-comments" class="activity-block table-view-list">';
1119          echo '<h3>' . __( 'Recent Comments' ) . '</h3>';
1120  
1121          echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
1122          foreach ( $comments as $comment ) {
1123              _wp_dashboard_recent_comments_row( $comment );
1124          }
1125          echo '</ul>';
1126  
1127          if ( current_user_can( 'edit_posts' ) ) {
1128              echo '<h3 class="screen-reader-text">' .
1129                  /* translators: Hidden accessibility text. */
1130                  __( 'View more comments' ) .
1131              '</h3>';
1132              _get_list_table( 'WP_Comments_List_Table' )->views();
1133          }
1134  
1135          wp_comment_reply( -1, false, 'dashboard', false );
1136          wp_comment_trashnotice();
1137  
1138          echo '</div>';
1139      } else {
1140          return false;
1141      }
1142      return true;
1143  }
1144  
1145  /**
1146   * Display generic dashboard RSS widget feed.
1147   *
1148   * @since 2.5.0
1149   *
1150   * @param string $widget_id
1151   */
1152  function wp_dashboard_rss_output( $widget_id ) {
1153      $widgets = get_option( 'dashboard_widget_options' );
1154      echo '<div class="rss-widget">';
1155      wp_widget_rss_output( $widgets[ $widget_id ] );
1156      echo '</div>';
1157  }
1158  
1159  /**
1160   * Checks to see if all of the feed url in $check_urls are cached.
1161   *
1162   * If $check_urls is empty, look for the rss feed url found in the dashboard
1163   * widget options of $widget_id. If cached, call $callback, a function that
1164   * echoes out output for this widget. If not cache, echo a "Loading..." stub
1165   * which is later replaced by Ajax call (see top of /wp-admin/index.php)
1166   *
1167   * @since 2.5.0
1168   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
1169   *              by adding it to the function signature.
1170   *
1171   * @param string   $widget_id  The widget ID.
1172   * @param callable $callback   The callback function used to display each feed.
1173   * @param array    $check_urls RSS feeds.
1174   * @param mixed    ...$args    Optional additional parameters to pass to the callback function.
1175   * @return bool True on success, false on failure.
1176   */
1177  function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
1178      $doing_ajax = wp_doing_ajax();
1179      $loading    = '<p class="widget-loading hide-if-no-js">' . __( 'Loading&hellip;' ) . '</p>';
1180      $loading   .= wp_get_admin_notice(
1181          __( 'This widget requires JavaScript.' ),
1182          array(
1183              'type'               => 'error',
1184              'additional_classes' => array( 'inline', 'hide-if-js' ),
1185          )
1186      );
1187  
1188      if ( empty( $check_urls ) ) {
1189          $widgets = get_option( 'dashboard_widget_options' );
1190  
1191          if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
1192              echo $loading;
1193              return false;
1194          }
1195  
1196          $check_urls = array( $widgets[ $widget_id ]['url'] );
1197      }
1198  
1199      $locale    = get_user_locale();
1200      $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
1201      $output    = get_transient( $cache_key );
1202  
1203      if ( false !== $output ) {
1204          echo $output;
1205          return true;
1206      }
1207  
1208      if ( ! $doing_ajax ) {
1209          echo $loading;
1210          return false;
1211      }
1212  
1213      if ( $callback && is_callable( $callback ) ) {
1214          array_unshift( $args, $widget_id, $check_urls );
1215          ob_start();
1216          call_user_func_array( $callback, $args );
1217          // Default lifetime in cache of 12 hours (same as the feeds).
1218          set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );
1219      }
1220  
1221      return true;
1222  }
1223  
1224  //
1225  // Dashboard Widgets Controls.
1226  //
1227  
1228  /**
1229   * Calls widget control callback.
1230   *
1231   * @since 2.5.0
1232   *
1233   * @global callable[] $wp_dashboard_control_callbacks
1234   *
1235   * @param int|false $widget_control_id Optional. Registered widget ID. Default false.
1236   */
1237  function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
1238      global $wp_dashboard_control_callbacks;
1239  
1240      if ( is_scalar( $widget_control_id ) && $widget_control_id
1241          && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] )
1242          && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] )
1243      ) {
1244          call_user_func(
1245              $wp_dashboard_control_callbacks[ $widget_control_id ],
1246              '',
1247              array(
1248                  'id'       => $widget_control_id,
1249                  'callback' => $wp_dashboard_control_callbacks[ $widget_control_id ],
1250              )
1251          );
1252      }
1253  }
1254  
1255  /**
1256   * Sets up the RSS dashboard widget control and $args to be used as input to wp_widget_rss_form().
1257   *
1258   * Handles POST data from RSS-type widgets.
1259   *
1260   * @since 2.5.0
1261   *
1262   * @param string $widget_id
1263   * @param array  $form_inputs
1264   */
1265  function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
1266      $widget_options = get_option( 'dashboard_widget_options' );
1267  
1268      if ( ! $widget_options ) {
1269          $widget_options = array();
1270      }
1271  
1272      if ( ! isset( $widget_options[ $widget_id ] ) ) {
1273          $widget_options[ $widget_id ] = array();
1274      }
1275  
1276      $number = 1; // Hack to use wp_widget_rss_form().
1277  
1278      $widget_options[ $widget_id ]['number'] = $number;
1279  
1280      if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
1281          $_POST['widget-rss'][ $number ]         = wp_unslash( $_POST['widget-rss'][ $number ] );
1282          $widget_options[ $widget_id ]           = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
1283          $widget_options[ $widget_id ]['number'] = $number;
1284  
1285          // Title is optional. If black, fill it if possible.
1286          if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
1287              $rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
1288              if ( is_wp_error( $rss ) ) {
1289                  $widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
1290              } else {
1291                  $widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
1292                  $rss->__destruct();
1293                  unset( $rss );
1294              }
1295          }
1296  
1297          update_option( 'dashboard_widget_options', $widget_options, false );
1298  
1299          $locale    = get_user_locale();
1300          $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
1301          delete_transient( $cache_key );
1302      }
1303  
1304      wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
1305  }
1306  
1307  
1308  /**
1309   * Renders the Events and News dashboard widget.
1310   *
1311   * @since 4.8.0
1312   */
1313  function wp_dashboard_events_news() {
1314      wp_print_community_events_markup();
1315  
1316      ?>
1317  
1318      <div class="wordpress-news hide-if-no-js">
1319          <?php wp_dashboard_primary(); ?>
1320      </div>
1321  
1322      <p class="community-events-footer">
1323          <?php
1324              printf(
1325                  '<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>',
1326                  'https://make.wordpress.org/community/meetups-landing-page',
1327                  __( 'Meetups' ),
1328                  /* translators: Hidden accessibility text. */
1329                  __( '(opens in a new tab)' )
1330              );
1331          ?>
1332  
1333          |
1334  
1335          <?php
1336              printf(
1337                  '<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>',
1338                  'https://central.wordcamp.org/schedule/',
1339                  __( 'WordCamps' ),
1340                  /* translators: Hidden accessibility text. */
1341                  __( '(opens in a new tab)' )
1342              );
1343          ?>
1344  
1345          |
1346  
1347          <?php
1348              printf(
1349                  '<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>',
1350                  /* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */
1351                  esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ),
1352                  __( 'News' ),
1353                  /* translators: Hidden accessibility text. */
1354                  __( '(opens in a new tab)' )
1355              );
1356          ?>
1357      </p>
1358  
1359      <?php
1360  }
1361  
1362  /**
1363   * Prints the markup for the Community Events section of the Events and News Dashboard widget.
1364   *
1365   * @since 4.8.0
1366   */
1367  function wp_print_community_events_markup() {
1368      $community_events_notice  = '<p class="hide-if-js">' . ( 'This widget requires JavaScript.' ) . '</p>';
1369      $community_events_notice .= '<p class="community-events-error-occurred" aria-hidden="true">' . __( 'An error occurred. Please try again.' ) . '</p>';
1370      $community_events_notice .= '<p class="community-events-could-not-locate" aria-hidden="true"></p>';
1371  
1372      wp_admin_notice(
1373          $community_events_notice,
1374          array(
1375              'type'               => 'error',
1376              'additional_classes' => array( 'community-events-errors', 'inline', 'hide-if-js' ),
1377              'paragraph_wrap'     => false,
1378          )
1379      );
1380  
1381      /*
1382       * Hide the main element when the page first loads, because the content
1383       * won't be ready until wp.communityEvents.renderEventsTemplate() has run.
1384       */
1385      ?>
1386      <div id="community-events" class="community-events" aria-hidden="true">
1387          <div class="activity-block">
1388              <p>
1389                  <span id="community-events-location-message"></span>
1390  
1391                  <button class="button-link community-events-toggle-location" aria-expanded="false">
1392                      <span class="dashicons dashicons-location" aria-hidden="true"></span>
1393                      <span class="community-events-location-edit"><?php _e( 'Select location' ); ?></span>
1394                  </button>
1395              </p>
1396  
1397              <form class="community-events-form" aria-hidden="true" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
1398                  <label for="community-events-location">
1399                      <?php _e( 'City:' ); ?>
1400                  </label>
1401                  <?php
1402                  /* translators: Replace with a city related to your locale.
1403                   * Test that it matches the expected location and has upcoming
1404                   * events before including it. If no cities related to your
1405                   * locale have events, then use a city related to your locale
1406                   * that would be recognizable to most users. Use only the city
1407                   * name itself, without any region or country. Use the endonym
1408                   * (native locale name) instead of the English name if possible.
1409                   */
1410                  ?>
1411                  <input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />
1412  
1413                  <?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?>
1414  
1415                  <button class="community-events-cancel button-link" type="button" aria-expanded="false">
1416                      <?php _e( 'Cancel' ); ?>
1417                  </button>
1418  
1419                  <span class="spinner"></span>
1420              </form>
1421          </div>
1422  
1423          <ul class="community-events-results activity-block last"></ul>
1424      </div>
1425  
1426      <?php
1427  }
1428  
1429  /**
1430   * Renders the events templates for the Event and News widget.
1431   *
1432   * @since 4.8.0
1433   */
1434  function wp_print_community_events_templates() {
1435      ?>
1436  
1437      <script id="tmpl-community-events-attend-event-near" type="text/template">
1438          <?php
1439          printf(
1440              /* translators: %s: The name of a city. */
1441              __( 'Attend an upcoming event near %s.' ),
1442              '<strong>{{ data.location.description }}</strong>'
1443          );
1444          ?>
1445      </script>
1446  
1447      <script id="tmpl-community-events-could-not-locate" type="text/template">
1448          <?php
1449          printf(
1450              /* translators: %s is the name of the city we couldn't locate.
1451               * Replace the examples with cities in your locale, but test
1452               * that they match the expected location before including them.
1453               * Use endonyms (native locale names) whenever possible.
1454               */
1455              __( '%s could not be located. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
1456              '<em>{{data.unknownCity}}</em>'
1457          );
1458          ?>
1459      </script>
1460  
1461      <script id="tmpl-community-events-event-list" type="text/template">
1462          <# _.each( data.events, function( event ) { #>
1463              <li class="event event-{{ event.type }} wp-clearfix">
1464                  <div class="event-info">
1465                      <div class="dashicons event-icon" aria-hidden="true"></div>
1466                      <div class="event-info-inner">
1467                          <a class="event-title" href="{{ event.url }}">{{ event.title }}</a>
1468                          <# if ( event.type ) {
1469                              const titleCaseEventType = event.type.replace(
1470                                  /\w\S*/g,
1471                                  function ( type ) { return type.charAt(0).toUpperCase() + type.substr(1).toLowerCase(); }
1472                              );
1473                          #>
1474                              {{ 'wordcamp' === event.type ? 'WordCamp' : titleCaseEventType }}
1475                              <span class="ce-separator" aria-hidden="true"></span>
1476                          <# } #>
1477                          <span class="event-city">{{ event.location.location }}</span>
1478                      </div>
1479                  </div>
1480  
1481                  <div class="event-date-time">
1482                      <span class="event-date">{{ event.user_formatted_date }}</span>
1483                      <# if ( 'meetup' === event.type ) { #>
1484                          <span class="event-time">
1485                              {{ event.user_formatted_time }} {{ event.timeZoneAbbreviation }}
1486                          </span>
1487                      <# } #>
1488                  </div>
1489              </li>
1490          <# } ) #>
1491  
1492          <# if ( data.events.length <= 2 ) { #>
1493              <li class="event-none">
1494                  <?php
1495                  printf(
1496                      /* translators: %s: Localized meetup organization documentation URL. */
1497                      __( 'Want more events? <a href="%s">Help organize the next one</a>!' ),
1498                      __( 'https://make.wordpress.org/community/organize-event-landing-page/' )
1499                  );
1500                  ?>
1501              </li>
1502          <# } #>
1503  
1504      </script>
1505  
1506      <script id="tmpl-community-events-no-upcoming-events" type="text/template">
1507          <li class="event-none">
1508              <# if ( data.location.description ) { #>
1509                  <?php
1510                  printf(
1511                      /* translators: 1: The city the user searched for, 2: Meetup organization documentation URL. */
1512                      __( 'There are no events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize a WordPress event</a>?' ),
1513                      '{{ data.location.description }}',
1514                      __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
1515                  );
1516                  ?>
1517  
1518              <# } else { #>
1519                  <?php
1520                  printf(
1521                      /* translators: %s: Meetup organization documentation URL. */
1522                      __( 'There are no events scheduled near you at the moment. Would you like to <a href="%s">organize a WordPress event</a>?' ),
1523                      __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
1524                  );
1525                  ?>
1526              <# } #>
1527          </li>
1528      </script>
1529      <?php
1530  }
1531  
1532  /**
1533   * 'WordPress Events and News' dashboard widget.
1534   *
1535   * @since 2.7.0
1536   * @since 4.8.0 Removed popular plugins feed.
1537   */
1538  function wp_dashboard_primary() {
1539      $feeds = array(
1540          'news'   => array(
1541  
1542              /**
1543               * Filters the primary link URL for the 'WordPress Events and News' dashboard widget.
1544               *
1545               * @since 2.5.0
1546               *
1547               * @param string $link The widget's primary link URL.
1548               */
1549              'link'         => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ),
1550  
1551              /**
1552               * Filters the primary feed URL for the 'WordPress Events and News' dashboard widget.
1553               *
1554               * @since 2.3.0
1555               *
1556               * @param string $url The widget's primary feed URL.
1557               */
1558              'url'          => apply_filters( 'dashboard_primary_feed', __( 'https://wordpress.org/news/feed/' ) ),
1559  
1560              /**
1561               * Filters the primary link title for the 'WordPress Events and News' dashboard widget.
1562               *
1563               * @since 2.3.0
1564               *
1565               * @param string $title Title attribute for the widget's primary link.
1566               */
1567              'title'        => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
1568              'items'        => 2,
1569              'show_summary' => 0,
1570              'show_author'  => 0,
1571              'show_date'    => 0,
1572          ),
1573          'planet' => array(
1574  
1575              /**
1576               * Filters the secondary link URL for the 'WordPress Events and News' dashboard widget.
1577               *
1578               * @since 2.3.0
1579               *
1580               * @param string $link The widget's secondary link URL.
1581               */
1582              'link'         => apply_filters(
1583                  'dashboard_secondary_link',
1584                  /* translators: Link to the Planet website of the locale. */
1585                  __( 'https://planet.wordpress.org/' )
1586              ),
1587  
1588              /**
1589               * Filters the secondary feed URL for the 'WordPress Events and News' dashboard widget.
1590               *
1591               * @since 2.3.0
1592               *
1593               * @param string $url The widget's secondary feed URL.
1594               */
1595              'url'          => apply_filters(
1596                  'dashboard_secondary_feed',
1597                  /* translators: Link to the Planet feed of the locale. */
1598                  __( 'https://planet.wordpress.org/feed/' )
1599              ),
1600  
1601              /**
1602               * Filters the secondary link title for the 'WordPress Events and News' dashboard widget.
1603               *
1604               * @since 2.3.0
1605               *
1606               * @param string $title Title attribute for the widget's secondary link.
1607               */
1608              'title'        => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
1609  
1610              /**
1611               * Filters the number of secondary link items for the 'WordPress Events and News' dashboard widget.
1612               *
1613               * @since 4.4.0
1614               *
1615               * @param string $items How many items to show in the secondary feed.
1616               */
1617              'items'        => apply_filters( 'dashboard_secondary_items', 3 ),
1618              'show_summary' => 0,
1619              'show_author'  => 0,
1620              'show_date'    => 0,
1621          ),
1622      );
1623  
1624      wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
1625  }
1626  
1627  /**
1628   * Displays the WordPress events and news feeds.
1629   *
1630   * @since 3.8.0
1631   * @since 4.8.0 Removed popular plugins feed.
1632   *
1633   * @param string $widget_id Widget ID.
1634   * @param array  $feeds     Array of RSS feeds.
1635   */
1636  function wp_dashboard_primary_output( $widget_id, $feeds ) {
1637      foreach ( $feeds as $type => $args ) {
1638          $args['type'] = $type;
1639          echo '<div class="rss-widget">';
1640              wp_widget_rss_output( $args['url'], $args );
1641          echo '</div>';
1642      }
1643  }
1644  
1645  /**
1646   * Displays file upload quota on dashboard.
1647   *
1648   * Runs on the {@see 'activity_box_end'} hook in wp_dashboard_right_now().
1649   *
1650   * @since 3.0.0
1651   *
1652   * @return true|null True if not multisite, user can't upload files, or the space check option is disabled.
1653   */
1654  function wp_dashboard_quota() {
1655      if ( ! is_multisite() || ! current_user_can( 'upload_files' )
1656          || get_site_option( 'upload_space_check_disabled' )
1657      ) {
1658          return true;
1659      }
1660  
1661      $quota = get_space_allowed();
1662      $used  = get_space_used();
1663  
1664      if ( $used > $quota ) {
1665          $percentused = '100';
1666      } else {
1667          $percentused = ( $used / $quota ) * 100;
1668      }
1669  
1670      $used_class  = ( $percentused >= 70 ) ? ' warning' : '';
1671      $used        = round( $used, 2 );
1672      $percentused = number_format( $percentused );
1673  
1674      ?>
1675      <h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3>
1676      <div class="mu-storage">
1677      <ul>
1678          <li class="storage-count">
1679              <?php
1680              $text = sprintf(
1681                  /* translators: %s: Number of megabytes. */
1682                  __( '%s MB Space Allowed' ),
1683                  number_format_i18n( $quota )
1684              );
1685              printf(
1686                  '<a href="%1$s">%2$s<span class="screen-reader-text"> (%3$s)</span></a>',
1687                  esc_url( admin_url( 'upload.php' ) ),
1688                  $text,
1689                  /* translators: Hidden accessibility text. */
1690                  __( 'Manage Uploads' )
1691              );
1692              ?>
1693          </li><li class="storage-count <?php echo $used_class; ?>">
1694              <?php
1695              $text = sprintf(
1696                  /* translators: 1: Number of megabytes, 2: Percentage. */
1697                  __( '%1$s MB (%2$s%%) Space Used' ),
1698                  number_format_i18n( $used, 2 ),
1699                  $percentused
1700              );
1701              printf(
1702                  '<a href="%1$s" class="musublink">%2$s<span class="screen-reader-text"> (%3$s)</span></a>',
1703                  esc_url( admin_url( 'upload.php' ) ),
1704                  $text,
1705                  /* translators: Hidden accessibility text. */
1706                  __( 'Manage Uploads' )
1707              );
1708              ?>
1709          </li>
1710      </ul>
1711      </div>
1712      <?php
1713      return null;
1714  }
1715  
1716  /**
1717   * Displays the browser update nag.
1718   *
1719   * @since 3.2.0
1720   * @since 5.8.0 Added a special message for Internet Explorer users.
1721   *
1722   * @global bool $is_IE
1723   */
1724  function wp_dashboard_browser_nag() {
1725      global $is_IE;
1726  
1727      $notice   = '';
1728      $response = wp_check_browser_version();
1729  
1730      if ( $response ) {
1731          if ( $is_IE ) {
1732              $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.' );
1733          } elseif ( $response['insecure'] ) {
1734              $msg = sprintf(
1735                  /* translators: %s: Browser name and link. */
1736                  __( "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." ),
1737                  sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
1738              );
1739          } else {
1740              $msg = sprintf(
1741                  /* translators: %s: Browser name and link. */
1742                  __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ),
1743                  sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) )
1744              );
1745          }
1746  
1747          $browser_nag_class = '';
1748          if ( ! empty( $response['img_src'] ) ) {
1749              $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) ) ? $response['img_src_ssl'] : $response['img_src'];
1750  
1751              $notice           .= '<div class="alignright browser-icon"><img src="' . esc_url( $img_src ) . '" alt="" /></div>';
1752              $browser_nag_class = ' has-browser-icon';
1753          }
1754          $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
1755  
1756          $browsehappy = 'https://browsehappy.com/';
1757          $locale      = get_user_locale();
1758          if ( 'en_US' !== $locale ) {
1759              $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
1760          }
1761  
1762          if ( $is_IE ) {
1763              $msg_browsehappy = sprintf(
1764                  /* translators: %s: Browse Happy URL. */
1765                  __( 'Learn how to <a href="%s" class="update-browser-link">browse happy</a>' ),
1766                  esc_url( $browsehappy )
1767              );
1768          } else {
1769              $msg_browsehappy = sprintf(
1770                  /* translators: 1: Browser update URL, 2: Browser name, 3: Browse Happy URL. */
1771                  __( '<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>' ),
1772                  esc_attr( $response['update_url'] ),
1773                  esc_html( $response['name'] ),
1774                  esc_url( $browsehappy )
1775              );
1776          }
1777  
1778          $notice .= '<p>' . $msg_browsehappy . '</p>';
1779          $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss" aria-label="' . esc_attr__( 'Dismiss the browser warning panel' ) . '">' . __( 'Dismiss' ) . '</a></p>';
1780          $notice .= '<div class="clear"></div>';
1781      }
1782  
1783      /**
1784       * Filters the notice output for the 'Browse Happy' nag meta box.
1785       *
1786       * @since 3.2.0
1787       *
1788       * @param string      $notice   The notice content.
1789       * @param array|false $response An array containing web browser information, or
1790       *                              false on failure. See wp_check_browser_version().
1791       */
1792      echo apply_filters( 'browse-happy-notice', $notice, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1793  }
1794  
1795  /**
1796   * Adds an additional class to the browser nag if the current version is insecure.
1797   *
1798   * @since 3.2.0
1799   *
1800   * @param string[] $classes Array of meta box classes.
1801   * @return string[] Modified array of meta box classes.
1802   */
1803  function dashboard_browser_nag_class( $classes ) {
1804      $response = wp_check_browser_version();
1805  
1806      if ( $response && $response['insecure'] ) {
1807          $classes[] = 'browser-insecure';
1808      }
1809  
1810      return $classes;
1811  }
1812  
1813  /**
1814   * Checks if the user needs a browser update.
1815   *
1816   * @since 3.2.0
1817   *
1818   * @return array|false Array of browser data on success, false on failure.
1819   */
1820  function wp_check_browser_version() {
1821      if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
1822          return false;
1823      }
1824  
1825      $key = md5( $_SERVER['HTTP_USER_AGENT'] );
1826  
1827      $response = get_site_transient( 'browser_' . $key );
1828  
1829      if ( false === $response ) {
1830          $url     = 'http://api.wordpress.org/core/browse-happy/1.1/';
1831          $options = array(
1832              'body'       => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
1833              'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),
1834          );
1835  
1836          if ( wp_http_supports( array( 'ssl' ) ) ) {
1837              $url = set_url_scheme( $url, 'https' );
1838          }
1839  
1840          $response = wp_remote_post( $url, $options );
1841  
1842          if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
1843              return false;
1844          }
1845  
1846          /**
1847           * Response should be an array with:
1848           *  'platform' - string - A user-friendly platform name, if it can be determined
1849           *  'name' - string - A user-friendly browser name
1850           *  'version' - string - The version of the browser the user is using
1851           *  'current_version' - string - The most recent version of the browser
1852           *  'upgrade' - boolean - Whether the browser needs an upgrade
1853           *  'insecure' - boolean - Whether the browser is deemed insecure
1854           *  'update_url' - string - The url to visit to upgrade
1855           *  'img_src' - string - An image representing the browser
1856           *  'img_src_ssl' - string - An image (over SSL) representing the browser
1857           */
1858          $response = json_decode( wp_remote_retrieve_body( $response ), true );
1859  
1860          if ( ! is_array( $response ) ) {
1861              return false;
1862          }
1863  
1864          set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
1865      }
1866  
1867      return $response;
1868  }
1869  
1870  /**
1871   * Displays the PHP update nag.
1872   *
1873   * @since 5.1.0
1874   */
1875  function wp_dashboard_php_nag() {
1876      $response = wp_check_php_version();
1877  
1878      if ( ! $response ) {
1879          return;
1880      }
1881  
1882      if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
1883          // The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates.
1884  
1885          if ( $response['is_lower_than_future_minimum'] ) {
1886              $message = sprintf(
1887                  /* translators: %s: The server PHP version. */
1888                  __( '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.' ),
1889                  PHP_VERSION
1890              );
1891          } else {
1892              $message = sprintf(
1893                  /* translators: %s: The server PHP version. */
1894                  __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates. It should be updated.' ),
1895                  PHP_VERSION
1896              );
1897          }
1898      } elseif ( $response['is_lower_than_future_minimum'] ) {
1899          $message = sprintf(
1900              /* translators: %s: The server PHP version. */
1901              __( '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.' ),
1902              PHP_VERSION
1903          );
1904      } else {
1905          $message = sprintf(
1906              /* translators: %s: The server PHP version. */
1907              __( 'Your site is running on an outdated version of PHP (%s), which should be updated.' ),
1908              PHP_VERSION
1909          );
1910      }
1911      ?>
1912      <p class="bigger-bolder-text"><?php echo $message; ?></p>
1913  
1914      <p><?php _e( 'What is PHP and how does it affect my site?' ); ?></p>
1915      <p>
1916          <?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.' ); ?>
1917          <?php
1918          if ( ! empty( $response['recommended_version'] ) ) {
1919              printf(
1920                  /* translators: %s: The minimum recommended PHP version. */
1921                  __( 'The minimum recommended version of PHP is %s.' ),
1922                  $response['recommended_version']
1923              );
1924          }
1925          ?>
1926      </p>
1927  
1928      <p class="button-container">
1929          <?php
1930          printf(
1931              '<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>',
1932              esc_url( wp_get_update_php_url() ),
1933              __( 'Learn more about updating PHP' ),
1934              /* translators: Hidden accessibility text. */
1935              __( '(opens in a new tab)' )
1936          );
1937          ?>
1938      </p>
1939      <?php
1940  
1941      wp_update_php_annotation();
1942      wp_direct_php_update_button();
1943  }
1944  
1945  /**
1946   * Adds an additional class to the PHP nag if the current version is insecure.
1947   *
1948   * @since 5.1.0
1949   *
1950   * @param string[] $classes Array of meta box classes.
1951   * @return string[] Modified array of meta box classes.
1952   */
1953  function dashboard_php_nag_class( $classes ) {
1954      $response = wp_check_php_version();
1955  
1956      if ( ! $response ) {
1957          return $classes;
1958      }
1959  
1960      if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) {
1961          $classes[] = 'php-no-security-updates';
1962      } elseif ( $response['is_lower_than_future_minimum'] ) {
1963          $classes[] = 'php-version-lower-than-future-minimum';
1964      }
1965  
1966      return $classes;
1967  }
1968  
1969  /**
1970   * Displays the Site Health Status widget.
1971   *
1972   * @since 5.4.0
1973   */
1974  function wp_dashboard_site_health() {
1975      $get_issues = get_transient( 'health-check-site-status-result' );
1976  
1977      $issue_counts = array();
1978  
1979      if ( false !== $get_issues ) {
1980          $issue_counts = json_decode( $get_issues, true );
1981      }
1982  
1983      if ( ! is_array( $issue_counts ) || ! $issue_counts ) {
1984          $issue_counts = array(
1985              'good'        => 0,
1986              'recommended' => 0,
1987              'critical'    => 0,
1988          );
1989      }
1990  
1991      $issues_total = $issue_counts['recommended'] + $issue_counts['critical'];
1992      ?>
1993      <div class="health-check-widget">
1994          <div class="health-check-widget-title-section site-health-progress-wrapper loading hide-if-no-js">
1995              <div class="site-health-progress">
1996                  <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">
1997                      <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
1998                      <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
1999                  </svg>
2000              </div>
2001              <div class="site-health-progress-label">
2002                  <?php if ( false === $get_issues ) : ?>
2003                      <?php _e( 'No information yet&hellip;' ); ?>
2004                  <?php else : ?>
2005                      <?php _e( 'Results are still loading&hellip;' ); ?>
2006                  <?php endif; ?>
2007              </div>
2008          </div>
2009  
2010          <div class="site-health-details">
2011              <?php if ( false === $get_issues ) : ?>
2012                  <p>
2013                      <?php
2014                      printf(
2015                          /* translators: %s: URL to Site Health screen. */
2016                          __( '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.' ),
2017                          esc_url( admin_url( 'site-health.php' ) )
2018                      );
2019                      ?>
2020                  </p>
2021              <?php else : ?>
2022                  <p>
2023                      <?php if ( $issues_total <= 0 ) : ?>
2024                          <?php _e( 'Great job! Your site currently passes all site health checks.' ); ?>
2025                      <?php elseif ( 1 === (int) $issue_counts['critical'] ) : ?>
2026                          <?php _e( 'Your site has a critical issue that should be addressed as soon as possible to improve its performance and security.' ); ?>
2027                      <?php elseif ( $issue_counts['critical'] > 1 ) : ?>
2028                          <?php _e( 'Your site has critical issues that should be addressed as soon as possible to improve its performance and security.' ); ?>
2029                      <?php elseif ( 1 === (int) $issue_counts['recommended'] ) : ?>
2030                          <?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.' ); ?>
2031                      <?php else : ?>
2032                          <?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.' ); ?>
2033                      <?php endif; ?>
2034                  </p>
2035              <?php endif; ?>
2036  
2037              <?php if ( $issues_total > 0 && false !== $get_issues ) : ?>
2038                  <p>
2039                      <?php
2040                      printf(
2041                          /* translators: 1: Number of issues. 2: URL to Site Health screen. */
2042                          _n(
2043                              'Take a look at the <strong>%1$d item</strong> on the <a href="%2$s">Site Health screen</a>.',
2044                              'Take a look at the <strong>%1$d items</strong> on the <a href="%2$s">Site Health screen</a>.',
2045                              $issues_total
2046                          ),
2047                          $issues_total,
2048                          esc_url( admin_url( 'site-health.php' ) )
2049                      );
2050                      ?>
2051                  </p>
2052              <?php endif; ?>
2053          </div>
2054      </div>
2055  
2056      <?php
2057  }
2058  
2059  /**
2060   * Outputs empty dashboard widget to be populated by JS later.
2061   *
2062   * Usable by plugins.
2063   *
2064   * @since 2.5.0
2065   */
2066  function wp_dashboard_empty() {}
2067  
2068  /**
2069   * Displays a welcome panel to introduce users to WordPress.
2070   *
2071   * @since 3.3.0
2072   * @since 5.9.0 Send users to the Site Editor if the active theme is block-based.
2073   */
2074  function wp_welcome_panel() {
2075      list( $display_version ) = explode( '-', wp_get_wp_version() );
2076      $can_customize           = current_user_can( 'customize' );
2077      $is_block_theme          = wp_is_block_theme();
2078      ?>
2079      <div class="welcome-panel-content">
2080      <div class="welcome-panel-header-wrap">
2081          <div class="welcome-panel-header">
2082              <div class="welcome-panel-header-image">
2083                  <?php echo file_get_contents( dirname( __DIR__ ) . '/images/dashboard-background.svg' ); ?>
2084              </div>
2085              <h2><?php _e( 'Welcome to WordPress!' ); ?></h2>
2086              <p>
2087                  <a href="<?php echo esc_url( admin_url( 'about.php' ) ); ?>">
2088                  <?php
2089                      /* translators: %s: Current WordPress version. */
2090                      printf( __( 'Learn more about the %s version.' ), esc_html( $display_version ) );
2091                  ?>
2092                  </a>
2093              </p>
2094          </div>
2095      </div>
2096      <div class="welcome-panel-column-container">
2097          <div class="welcome-panel-column">
2098              <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
2099                  <rect width="48" height="48" rx="4" fill="#1E1E1E"/>
2100                  <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"/>
2101              </svg>
2102              <div class="welcome-panel-column-content">
2103                  <h3><?php _e( 'Author rich content with blocks and patterns' ); ?></h3>
2104                  <p><?php _e( 'Block patterns are pre-configured block layouts. Use them to get inspired or create new pages in a flash.' ); ?></p>
2105                  <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page' ) ); ?>"><?php _e( 'Add a new page' ); ?></a>
2106              </div>
2107          </div>
2108          <div class="welcome-panel-column">
2109              <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
2110                  <rect width="48" height="48" rx="4" fill="#1E1E1E"/>
2111                  <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"/>
2112              </svg>
2113              <div class="welcome-panel-column-content">
2114              <?php if ( $is_block_theme ) : ?>
2115                  <h3><?php _e( 'Customize your entire site with block themes' ); ?></h3>
2116                  <p><?php _e( 'Design everything on your site &#8212; from the header down to the footer, all using blocks and patterns.' ); ?></p>
2117                  <a href="<?php echo esc_url( admin_url( 'site-editor.php' ) ); ?>"><?php _e( 'Open site editor' ); ?></a>
2118              <?php else : ?>
2119                  <h3><?php _e( 'Start Customizing' ); ?></h3>
2120                  <p><?php _e( 'Configure your site&#8217;s logo, header, menus, and more in the Customizer.' ); ?></p>
2121                  <?php if ( $can_customize ) : ?>
2122                      <a class="load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Open the Customizer' ); ?></a>
2123                  <?php endif; ?>
2124              <?php endif; ?>
2125              </div>
2126          </div>
2127          <div class="welcome-panel-column">
2128              <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
2129                  <rect width="48" height="48" rx="4" fill="#1E1E1E"/>
2130                  <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"/>
2131              </svg>
2132              <div class="welcome-panel-column-content">
2133              <?php if ( $is_block_theme ) : ?>
2134                  <h3><?php _e( 'Switch up your site&#8217;s look & feel with Styles' ); ?></h3>
2135                  <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>
2136                  <a href="<?php echo esc_url( add_query_arg( 'p', rawurlencode( '/styles' ), admin_url( 'site-editor.php' ) ) ); ?>"><?php _e( 'Edit styles' ); ?></a>
2137              <?php else : ?>
2138                  <h3><?php _e( 'Discover a new way to build your site.' ); ?></h3>
2139                  <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>
2140                  <a href="<?php echo esc_url( __( 'https://wordpress.org/documentation/article/block-themes/' ) ); ?>"><?php _e( 'Learn about block themes' ); ?></a>
2141              <?php endif; ?>
2142              </div>
2143          </div>
2144      </div>
2145      </div>
2146      <?php
2147  }


Generated : Fri May 8 08:20:02 2026 Cross-referenced by PHPXref