wppaste
WordPress

WP_Site_Health::enqueue_scripts()

Since
5.2.0
Source
wp-admin/includes/class-wp-site-health.php:92
Enqueues the site health scripts.

Compatibility

WordPress
since 5.2.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Performance profile

How much work a call to WP_Site_Health::enqueue_scripts() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
10–66

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 131.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • transienttransientget_transient()called directly
  • serializeserialisationjson_decode()called directly
  • hookthird-party callbacksapply_filters()one call below WP_Site_Health::enqueue_scripts()
  • cacheobject cachewp_cache_get()one call below WP_Site_Health::enqueue_scripts()
  • optionoption read or writeget_option()one call below WP_Site_Health::enqueue_scripts()

Further down the call graph this can also reach query. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 5 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health::enqueue_scripts() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always10get_current_screen()
$issue_counts === false34–43get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), wp_localize_script()
$issue_counts !== false41–50get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), json_decode(), wp_localize_script()
$issue_counts === false49–59get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), ::WP_Site_Health(), ->is_development_environment(), wp_localize_script()
$issue_counts !== false56–66get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), json_decode(), ::WP_Site_Health(), ->is_development_environment(), wp_localize_script()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev13110–6618
8.513110–6618
8.413110–66183 fewer instructions than PHP 8.3
8.313410–6618
8.213410–6618
8.113410–6618
7.413410–6618

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 7

Source code

	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'  => $test['has_rest'] ?? false,						'completed' => false,						'headers'   => $test['headers'] ?? array(),					);				}			}		} 		wp_localize_script( 'site-health', 'SiteHealth', $health_check_js_variables );	}

Changelog

Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-admin/includes/class-wp-site-health.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.