balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

site-health.php (8710B)


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