Source
File: wp-admin/includes/class-wp-site-health.php
public function enqueue_scripts() {
$screen = get_current_screen();
if ( 'site-health' !== $screen->id && 'dashboard' !== $screen->id ) {
return;
}
$health_check_js_variables = array(
'screen' => $screen->id,
'nonce' => array(
'site_status' => wp_create_nonce( 'health-check-site-status' ),
'site_status_result' => wp_create_nonce( 'health-check-site-status-result' ),
),
'site_status' => array(
'direct' => array(),
'async' => array(),
'issues' => array(
'good' => 0,
'recommended' => 0,
'critical' => 0,
),
),
);
$issue_counts = get_transient( 'health-check-site-status-result' );
if ( false !== $issue_counts ) {
$issue_counts = json_decode( $issue_counts );
$health_check_js_variables['site_status']['issues'] = $issue_counts;
}
if ( 'site-health' === $screen->id && ! isset( $_GET['tab'] ) ) {
$tests = WP_Site_Health::get_tests();
// Don't run https test on localhost.
if ( 'localhost' === preg_replace( '|https?://|', '', get_site_url() ) ) {
unset( $tests['direct']['https_status'] );
}
foreach ( $tests['direct'] as $test ) {
if ( is_string( $test['test'] ) ) {
$test_function = sprintf(
'get_test_%s',
$test['test']
);
if ( method_exists( $this, $test_function ) && is_callable( array( $this, $test_function ) ) ) {
$health_check_js_variables['site_status']['direct'][] = $this->perform_test( array( $this, $test_function ) );
continue;
}
}
if ( is_callable( $test['test'] ) ) {
$health_check_js_variables['site_status']['direct'][] = $this->perform_test( $test['test'] );
}
}
foreach ( $tests['async'] as $test ) {
if ( is_string( $test['test'] ) ) {
$health_check_js_variables['site_status']['async'][] = array(
'test' => $test['test'],
'completed' => false,
);
}
}
}
wp_localize_script( 'site-health', 'SiteHealth', $health_check_js_variables );
}