WP_Site_Health::get_test_wordpress_version(): array
- Since
- 5.2.0
- Source
wp-admin/includes/class-wp-site-health.php:254
Description
Gives various results depending on what kind of updates are available, if any, to encourage the user to install security updates as a priority.
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.
Return value
array- The test result.
Performance profile
How much work a call to WP_Site_Health::get_test_wordpress_version() 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
- 23–56
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_site_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 161.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionnetwork option
get_site_option()one call below WP_Site_Health::get_test_wordpress_version() - transienttransient
get_site_transient()one call below WP_Site_Health::get_test_wordpress_version() - hookthird-party callbacks
apply_filters()one call below WP_Site_Health::get_test_wordpress_version()
Further down the call graph this can also reach cache, serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Site_Health::get_test_wordpress_version() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_array($core_updates) | 23–24 | __(), wp_get_wp_version(), get_core_updates() |
!is_array($core_updates) | 56 | __(), wp_get_wp_version(), get_core_updates(), __(), sprintf(), __(), admin_url(), esc_url(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 161 | 23–56 | 5 | |
| 8.5 | 161 | 23–56 | 5 | |
| 8.4 | 161 | 23–56 | 5 | 4 fewer instructions than PHP 8.3 |
| 8.3 | 165 | 23–57 | 5 | |
| 8.2 | 165 | 23–57 | 5 | |
| 8.1 | 165 | 23–57 | 5 | |
| 7.4 | 165 | 23–57 | 5 |
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 · 5
- __()Retrieves the translation of $text.
- wp_get_wp_version()Returns the current WordPress version.
- get_core_updates()Gets available core updates.
- esc_url()Checks and cleans a URL.
- admin_url()Retrieves the URL to the admin area for the current site.
Source code
public function get_test_wordpress_version() { $result = array( 'label' => '', 'status' => '', 'badge' => array( 'label' => __( 'Performance' ), 'color' => 'blue', ), 'description' => '', 'actions' => '', 'test' => 'wordpress_version', ); $core_current_version = wp_get_wp_version(); $core_updates = get_core_updates(); if ( ! is_array( $core_updates ) ) { $result['status'] = 'recommended'; $result['label'] = sprintf( /* translators: %s: Your current version of WordPress. */ __( 'WordPress version %s' ), $core_current_version ); $result['description'] = sprintf( '<p>%s</p>', __( 'Unable to check if any new versions of WordPress are available.' ) ); $result['actions'] = sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'update-core.php?force-check=1' ) ), __( 'Check for updates manually' ) ); } else { foreach ( $core_updates as $core => $update ) { if ( 'upgrade' === $update->response ) { $current_version = explode( '.', $core_current_version ); $new_version = explode( '.', $update->version ); $current_major = $current_version[0] . '.' . $current_version[1]; $new_major = $new_version[0] . '.' . $new_version[1]; $result['label'] = sprintf( /* translators: %s: The latest version of WordPress available. */ __( 'WordPress update available (%s)' ), $update->version ); $result['actions'] = sprintf( '<a href="%s">%s</a>', esc_url( admin_url( 'update-core.php' ) ), __( 'Install the latest version of WordPress' ) ); if ( $current_major !== $new_major ) { // This is a major version mismatch. $result['status'] = 'recommended'; $result['description'] = sprintf( '<p>%s</p>', __( 'A new version of WordPress is available.' ) ); } else { // This is a minor version, sometimes considered more critical. $result['status'] = 'critical'; $result['badge']['label'] = __( 'Security' ); $result['description'] = sprintf( '<p>%s</p>', __( 'A new minor update is available for your site. Because minor updates often address security, it’s important to install them.' ) ); } } else { $result['status'] = 'good'; $result['label'] = sprintf( /* translators: %s: The current version of WordPress installed on this site. */ __( 'Your version of WordPress (%s) is up to date' ), $core_current_version );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.9.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.