[ Index ]

PHP Cross Reference of WordPress

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


Generated: Mon Jul 6 01:00:03 2020 Cross-referenced by PHPXref 0.7.1