WordPress at Your Fingertips
function is not described

WP_Site_Health::enqueue_scripts() public WP 5.2.0

Enqueues the site health scripts.

{} It's a method of the class: WP_Site_Health{}

No Hooks.

Return

null. Nothing.

Usage

$WP_Site_Health = new WP_Site_Health();
$WP_Site_Health->enqueue_scripts();

Changelog

Since 5.2.0 Introduced.

Code of WP_Site_Health::enqueue_scripts() WP 5.8.2

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'] ) || empty( $_GET['tab'] ) ) ) {
		$tests = WP_Site_Health::get_tests();

		// Don't run https test on development environments.
		if ( $this->is_development_environment() ) {
			unset( $tests['async']['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'],
					'has_rest'  => ( isset( $test['has_rest'] ) ? $test['has_rest'] : false ),
					'completed' => false,
					'headers'   => isset( $test['headers'] ) ? $test['headers'] : array(),
				);
			}
		}
	}

	wp_localize_script( 'site-health', 'SiteHealth', $health_check_js_variables );
}