[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/ -> site-health.php (source)

   1  <?php
   2  /**
   3   * Tools Administration Screen.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once  __DIR__ . '/admin.php';
  11  
  12  wp_reset_vars( array( 'action' ) );
  13  
  14  $tabs = array(
  15      /* translators: Tab heading for Site Health Status page. */
  16      ''      => _x( 'Status', 'Site Health' ),
  17      /* translators: Tab heading for Site Health Info page. */
  18      'debug' => _x( 'Info', 'Site Health' ),
  19  );
  20  
  21  /**
  22   * An associated array of extra tabs for the Site Health navigation bar.
  23   *
  24   * Add a custom page to the Site Health screen, based on a tab slug and label.
  25   * The label you provide will also be used as part of the site title.
  26   *
  27   * @since 5.8.0
  28   *
  29   * @param array $tabs An associated array of tab slugs and their label.
  30   */
  31  $tabs = apply_filters( 'site_health_navigation_tabs', $tabs );
  32  
  33  $wrapper_classes = array(
  34      'health-check-tabs-wrapper',
  35      'hide-if-no-js',
  36      'tab-count-' . count( $tabs ),
  37  );
  38  
  39  $title = sprintf(
  40      // translators: %s: The currently displayed tab.
  41      __( 'Site Health %s' ),
  42      ( isset( $_GET['tab'] ) ? esc_html( $tabs[ $_GET['tab'] ] ) : esc_html( reset( $tabs ) ) )
  43  );
  44  
  45  if ( ! current_user_can( 'view_site_health_checks' ) ) {
  46      wp_die( __( 'Sorry, you are not allowed to access site health information.' ), '', 403 );
  47  }
  48  
  49  wp_enqueue_style( 'site-health' );
  50  wp_enqueue_script( 'site-health' );
  51  
  52  if ( ! class_exists( 'WP_Site_Health' ) ) {
  53      require_once  ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
  54  }
  55  
  56  if ( 'update_https' === $action ) {
  57      check_admin_referer( 'wp_update_https' );
  58  
  59      if ( ! current_user_can( 'update_https' ) ) {
  60          wp_die( __( 'Sorry, you are not allowed to update this site to HTTPS.' ), 403 );
  61      }
  62  
  63      if ( ! wp_is_https_supported() ) {
  64          wp_die( __( 'It looks like HTTPS is not supported for your website at this point.' ) );
  65      }
  66  
  67      $result = wp_update_urls_to_https();
  68  
  69      wp_redirect( add_query_arg( 'https_updated', (int) $result, wp_get_referer() ) );
  70      exit;
  71  }
  72  
  73  $health_check_site_status = WP_Site_Health::get_instance();
  74  
  75  // Start by checking if this is a special request checking for the existence of certain filters.
  76  $health_check_site_status->check_wp_version_check_exists();
  77  
  78  require_once ABSPATH . 'wp-admin/admin-header.php';
  79  ?>
  80  <div class="health-check-header">
  81      <div class="health-check-title-section">
  82          <h1>
  83              <?php _e( 'Site Health' ); ?>
  84          </h1>
  85      </div>
  86  
  87      <?php
  88      if ( isset( $_GET['https_updated'] ) ) {
  89          if ( $_GET['https_updated'] ) {
  90              ?>
  91              <div id="message" class="notice notice-success is-dismissible"><p><?php _e( 'Site URLs switched to HTTPS.' ); ?></p></div>
  92              <?php
  93          } else {
  94              ?>
  95              <div id="message" class="notice notice-error is-dismissible"><p><?php _e( 'Site URLs could not be switched to HTTPS.' ); ?></p></div>
  96              <?php
  97          }
  98      }
  99      ?>
 100  
 101      <div class="health-check-title-section site-health-progress-wrapper loading hide-if-no-js">
 102          <div class="site-health-progress">
 103              <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">
 104                  <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
 105                  <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle>
 106              </svg>
 107          </div>
 108          <div class="site-health-progress-label">
 109              <?php _e( 'Results are still loading&hellip;' ); ?>
 110          </div>
 111      </div>
 112  
 113      <nav class="<?php echo implode( ' ', $wrapper_classes ); ?>" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
 114          <?php
 115          $tabs_slice = $tabs;
 116  
 117          /*
 118           * If there are more than 4 tabs, only output the first 3 inline,
 119           * the remaining links will be added to a sub-navigation.
 120           */
 121          if ( count( $tabs ) > 4 ) {
 122              $tabs_slice = array_slice( $tabs, 0, 3 );
 123          }
 124  
 125          foreach ( $tabs_slice as $slug => $label ) {
 126              printf(
 127                  '<a href="%s" class="health-check-tab %s">%s</a>',
 128                  esc_url(
 129                      add_query_arg(
 130                          array(
 131                              'tab' => $slug,
 132                          ),
 133                          admin_url( 'site-health.php' )
 134                      )
 135                  ),
 136                  ( isset( $_GET['tab'] ) && $_GET['tab'] === $slug ? 'active' : '' ),
 137                  esc_html( $label )
 138              );
 139          }
 140          ?>
 141  
 142          <?php if ( count( $tabs ) > 4 ) : ?>
 143              <button type="button" class="health-check-tab health-check-offscreen-nav-wrapper" aria-haspopup="true">
 144                  <span class="dashicons dashicons-ellipsis"></span>
 145                  <span class="screen-reader-text"><?php _e( 'Toggle extra menu items' ); ?></span>
 146  
 147                  <div class="health-check-offscreen-nav">
 148                      <?php
 149                      // Remove the first few entries from the array as being already output.
 150                      $tabs_slice = array_slice( $tabs, 3 );
 151                      foreach ( $tabs_slice as $slug => $label ) {
 152                          printf(
 153                              '<a href="%s" class="health-check-tab %s">%s</a>',
 154                              esc_url(
 155                                  add_query_arg(
 156                                      array(
 157                                          'tab' => $slug,
 158                                      ),
 159                                      admin_url( 'site-health.php' )
 160                                  )
 161                              ),
 162                              ( isset( $_GET['tab'] ) && $_GET['tab'] === $slug ? 'active' : '' ),
 163                              esc_html( $label )
 164                          );
 165                      }
 166                      ?>
 167                  </div>
 168              </button>
 169          <?php endif; ?>
 170      </nav>
 171  </div>
 172  
 173  <hr class="wp-header-end">
 174  
 175  <?php
 176  if ( isset( $_GET['tab'] ) && ! empty( $_GET['tab'] ) ) {
 177      /**
 178       * Output content of a custom Site Health tab.
 179       *
 180       * This action fires right after the Site Health header, and users are still subject to
 181       * the capability checks for the Site Health page to view any custom tabs and their contents.
 182       *
 183       * @since 5.8.0
 184       *
 185       * @param string $tab The slug of the tab that was requested.
 186       */
 187      do_action( 'site_health_tab_content', $_GET['tab'] );
 188  
 189      require_once ABSPATH . 'wp-admin/admin-footer.php';
 190      return;
 191  } else {
 192      ?>
 193  
 194  <div class="notice notice-error hide-if-js">
 195      <p><?php _e( 'The Site Health check requires JavaScript.' ); ?></p>
 196  </div>
 197  
 198  <div class="health-check-body health-check-status-tab hide-if-no-js">
 199      <div class="site-status-all-clear hide">
 200          <p class="icon">
 201              <span class="dashicons dashicons-yes"></span>
 202          </p>
 203  
 204          <p class="encouragement">
 205              <?php _e( 'Great job!' ); ?>
 206          </p>
 207  
 208          <p>
 209              <?php _e( 'Everything is running smoothly here.' ); ?>
 210          </p>
 211      </div>
 212  
 213      <div class="site-status-has-issues">
 214          <h2>
 215              <?php _e( 'Site Health Status' ); ?>
 216          </h2>
 217  
 218          <p><?php _e( 'The site health check shows critical information about your WordPress configuration and items that require your attention.' ); ?></p>
 219  
 220          <div class="site-health-issues-wrapper" id="health-check-issues-critical">
 221              <h3 class="site-health-issue-count-title">
 222                  <?php
 223                      /* translators: %s: Number of critical issues found. */
 224                      printf( _n( '%s critical issue', '%s critical issues', 0 ), '<span class="issue-count">0</span>' );
 225                  ?>
 226              </h3>
 227  
 228              <div id="health-check-site-status-critical" class="health-check-accordion issues"></div>
 229          </div>
 230  
 231          <div class="site-health-issues-wrapper" id="health-check-issues-recommended">
 232              <h3 class="site-health-issue-count-title">
 233                  <?php
 234                      /* translators: %s: Number of recommended improvements. */
 235                      printf( _n( '%s recommended improvement', '%s recommended improvements', 0 ), '<span class="issue-count">0</span>' );
 236                  ?>
 237              </h3>
 238  
 239              <div id="health-check-site-status-recommended" class="health-check-accordion issues"></div>
 240          </div>
 241      </div>
 242  
 243      <div class="site-health-view-more">
 244          <button type="button" class="button site-health-view-passed" aria-expanded="false" aria-controls="health-check-issues-good">
 245              <?php _e( 'Passed tests' ); ?>
 246              <span class="icon"></span>
 247          </button>
 248      </div>
 249  
 250      <div class="site-health-issues-wrapper hidden" id="health-check-issues-good">
 251          <h3 class="site-health-issue-count-title">
 252              <?php
 253                  /* translators: %s: Number of items with no issues. */
 254                  printf( _n( '%s item with no issues detected', '%s items with no issues detected', 0 ), '<span class="issue-count">0</span>' );
 255              ?>
 256          </h3>
 257  
 258          <div id="health-check-site-status-good" class="health-check-accordion issues"></div>
 259      </div>
 260  </div>
 261  
 262  <script id="tmpl-health-check-issue" type="text/template">
 263      <h4 class="health-check-accordion-heading">
 264          <button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-{{ data.test }}" type="button">
 265              <span class="title">{{ data.label }}</span>
 266              <# if ( data.badge ) { #>
 267                  <span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span>
 268              <# } #>
 269              <span class="icon"></span>
 270          </button>
 271      </h4>
 272      <div id="health-check-accordion-block-{{ data.test }}" class="health-check-accordion-panel" hidden="hidden">
 273          {{{ data.description }}}
 274          <# if ( data.actions ) { #>
 275              <div class="actions">
 276                  {{{ data.actions }}}
 277              </div>
 278          <# } #>
 279      </div>
 280  </script>
 281  
 282      <?php
 283  }
 284  require_once ABSPATH . 'wp-admin/admin-footer.php';


Generated: Sun Jun 13 01:00:04 2021 Cross-referenced by PHPXref 0.7.1