Aucune description

site-health.php 8.5KB

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