wp/wp-admin/site-health.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
--- a/wp/wp-admin/site-health.php	Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-admin/site-health.php	Wed Sep 21 18:19:35 2022 +0200
@@ -6,15 +6,43 @@
  * @subpackage Administration
  */
 
-if ( isset( $_GET['tab'] ) && 'debug' === $_GET['tab'] ) {
-	require_once __DIR__ . '/site-health-info.php';
-	return;
-}
-
 /** WordPress Administration Bootstrap */
 require_once __DIR__ . '/admin.php';
 
-$title = __( 'Site Health Status' );
+wp_reset_vars( array( 'action' ) );
+
+$tabs = array(
+	/* translators: Tab heading for Site Health Status page. */
+	''      => _x( 'Status', 'Site Health' ),
+	/* translators: Tab heading for Site Health Info page. */
+	'debug' => _x( 'Info', 'Site Health' ),
+);
+
+/**
+ * An associated array of extra tabs for the Site Health navigation bar.
+ *
+ * Add a custom page to the Site Health screen, based on a tab slug and label.
+ * The label you provide will also be used as part of the site title.
+ *
+ * @since 5.8.0
+ *
+ * @param array $tabs An associated array of tab slugs and their label.
+ */
+$tabs = apply_filters( 'site_health_navigation_tabs', $tabs );
+
+$wrapper_classes = array(
+	'health-check-tabs-wrapper',
+	'hide-if-no-js',
+	'tab-count-' . count( $tabs ),
+);
+
+$current_tab = ( isset( $_GET['tab'] ) ? $_GET['tab'] : '' );
+
+$title = sprintf(
+	// translators: %s: The currently displayed tab.
+	__( 'Site Health - %s' ),
+	( isset( $tabs[ $current_tab ] ) ? esc_html( $tabs[ $current_tab ] ) : esc_html( reset( $tabs ) ) )
+);
 
 if ( ! current_user_can( 'view_site_health_checks' ) ) {
 	wp_die( __( 'Sorry, you are not allowed to access site health information.' ), '', 403 );
@@ -27,6 +55,23 @@
 	require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
 }
 
+if ( 'update_https' === $action ) {
+	check_admin_referer( 'wp_update_https' );
+
+	if ( ! current_user_can( 'update_https' ) ) {
+		wp_die( __( 'Sorry, you are not allowed to update this site to HTTPS.' ), 403 );
+	}
+
+	if ( ! wp_is_https_supported() ) {
+		wp_die( __( 'It looks like HTTPS is not supported for your website at this point.' ) );
+	}
+
+	$result = wp_update_urls_to_https();
+
+	wp_redirect( add_query_arg( 'https_updated', (int) $result, wp_get_referer() ) );
+	exit;
+}
+
 $health_check_site_status = WP_Site_Health::get_instance();
 
 // Start by checking if this is a special request checking for the existence of certain filters.
@@ -41,6 +86,20 @@
 		</h1>
 	</div>
 
+	<?php
+	if ( isset( $_GET['https_updated'] ) ) {
+		if ( $_GET['https_updated'] ) {
+			?>
+			<div id="message" class="notice notice-success is-dismissible"><p><?php _e( 'Site URLs switched to HTTPS.' ); ?></p></div>
+			<?php
+		} else {
+			?>
+			<div id="message" class="notice notice-error is-dismissible"><p><?php _e( 'Site URLs could not be switched to HTTPS.' ); ?></p></div>
+			<?php
+		}
+	}
+	?>
+
 	<div class="health-check-title-section site-health-progress-wrapper loading hide-if-no-js">
 		<div class="site-health-progress">
 			<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">
@@ -53,30 +112,92 @@
 		</div>
 	</div>
 
-	<nav class="health-check-tabs-wrapper hide-if-no-js" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
-		<a href="<?php echo esc_url( admin_url( 'site-health.php' ) ); ?>" class="health-check-tab active" aria-current="true">
-			<?php
-			/* translators: Tab heading for Site Health Status page. */
-			_ex( 'Status', 'Site Health' );
-			?>
-		</a>
+	<nav class="<?php echo implode( ' ', $wrapper_classes ); ?>" aria-label="<?php esc_attr_e( 'Secondary menu' ); ?>">
+		<?php
+		$tabs_slice = $tabs;
+
+		/*
+		 * If there are more than 4 tabs, only output the first 3 inline,
+		 * the remaining links will be added to a sub-navigation.
+		 */
+		if ( count( $tabs ) > 4 ) {
+			$tabs_slice = array_slice( $tabs, 0, 3 );
+		}
+
+		foreach ( $tabs_slice as $slug => $label ) {
+			printf(
+				'<a href="%s" class="health-check-tab %s">%s</a>',
+				esc_url(
+					add_query_arg(
+						array(
+							'tab' => $slug,
+						),
+						admin_url( 'site-health.php' )
+					)
+				),
+				( $current_tab === $slug ? 'active' : '' ),
+				esc_html( $label )
+			);
+		}
+		?>
 
-		<a href="<?php echo esc_url( admin_url( 'site-health.php?tab=debug' ) ); ?>" class="health-check-tab">
-			<?php
-			/* translators: Tab heading for Site Health Info page. */
-			_ex( 'Info', 'Site Health' );
-			?>
-		</a>
+		<?php if ( count( $tabs ) > 4 ) : ?>
+			<button type="button" class="health-check-tab health-check-offscreen-nav-wrapper" aria-haspopup="true">
+				<span class="dashicons dashicons-ellipsis"></span>
+				<span class="screen-reader-text"><?php _e( 'Toggle extra menu items' ); ?></span>
+
+				<div class="health-check-offscreen-nav">
+					<?php
+					// Remove the first few entries from the array as being already output.
+					$tabs_slice = array_slice( $tabs, 3 );
+					foreach ( $tabs_slice as $slug => $label ) {
+						printf(
+							'<a href="%s" class="health-check-tab %s">%s</a>',
+							esc_url(
+								add_query_arg(
+									array(
+										'tab' => $slug,
+									),
+									admin_url( 'site-health.php' )
+								)
+							),
+							( isset( $_GET['tab'] ) && $_GET['tab'] === $slug ? 'active' : '' ),
+							esc_html( $label )
+						);
+					}
+					?>
+				</div>
+			</button>
+		<?php endif; ?>
 	</nav>
 </div>
 
 <hr class="wp-header-end">
 
+<?php
+if ( isset( $_GET['tab'] ) && ! empty( $_GET['tab'] ) ) {
+	/**
+	 * Output content of a custom Site Health tab.
+	 *
+	 * This action fires right after the Site Health header, and users are still subject to
+	 * the capability checks for the Site Health page to view any custom tabs and their contents.
+	 *
+	 * @since 5.8.0
+	 *
+	 * @param string $tab The slug of the tab that was requested.
+	 */
+	do_action( 'site_health_tab_content', $_GET['tab'] );
+
+	require_once ABSPATH . 'wp-admin/admin-footer.php';
+	return;
+} else {
+	?>
+
 <div class="notice notice-error hide-if-js">
 	<p><?php _e( 'The Site Health check requires JavaScript.' ); ?></p>
 </div>
 
-<div class="health-check-body hide-if-no-js">
+<div class="health-check-body health-check-status-tab hide-if-no-js">
 	<div class="site-status-all-clear hide">
 		<p class="icon">
 			<span class="dashicons dashicons-yes"></span>
@@ -144,7 +265,9 @@
 	<h4 class="health-check-accordion-heading">
 		<button aria-expanded="false" class="health-check-accordion-trigger" aria-controls="health-check-accordion-block-{{ data.test }}" type="button">
 			<span class="title">{{ data.label }}</span>
-			<span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span>
+			<# if ( data.badge ) { #>
+				<span class="badge {{ data.badge.color }}">{{ data.badge.label }}</span>
+			<# } #>
 			<span class="icon"></span>
 		</button>
 	</h4>
@@ -158,5 +281,6 @@
 	</div>
 </script>
 
-<?php
+	<?php
+}
 require_once ABSPATH . 'wp-admin/admin-footer.php';