WP_Site_Health::enqueue_scripts()
- Since
- 5.2.0
- Source
wp-admin/includes/class-wp-site-health.php:92
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
- Scaling
- Scales with input
- Instructions
- 10–66
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 135.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- transienttransient
get_transient()called directly - serializeserialisation
json_decode()called directly - hookthird-party callbacks
apply_filters()one call below WP_Site_Health::enqueue_scripts() - cacheobject cache
wp_cache_get()one call below WP_Site_Health::enqueue_scripts() - optionoption read or write
get_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 10 | get_current_screen() |
$issue_counts === false | 34–43 | get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), wp_localize_script() |
$issue_counts !== false | 41–50 | get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), json_decode(), wp_localize_script() |
$issue_counts === false | 49–59 | get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), ::WP_Site_Health(), ->is_development_environment(), wp_localize_script() |
$issue_counts !== false | 56–66 | get_current_screen(), wp_create_nonce(), wp_create_nonce(), get_transient(), json_decode(), ::WP_Site_Health(), ->is_development_environment(), wp_localize_script() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 135 | 10–66 | 18 | |
| 8.5 | 135 | 10–66 | 18 | |
| 8.4 | 135 | 10–66 | 18 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 138 | 10–66 | 18 | |
| 8.2 | 138 | 10–66 | 18 | |
| 8.1 | 138 | 10–66 | 18 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 140 | 10–66 | 18 |
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
- get_current_screen()Get the current screen object
- wp_create_nonce()Creates a cryptographic token tied to a specific action, user, user session, and window of time.
- get_transient()Retrieves the value of a transient.
- wp_localize_script()Localizes a script.
- WP_Site_Health::get_tests()Returns a set of tests that belong to the site status page.
- WP_Site_Health::is_development_environment()Checks if the current environment type is set to 'development' or 'local'.
- WP_Site_Health::perform_test()Runs a Site Health test directly.
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' => ( 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 ); }Changelog
Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 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.