WP_Site_Health::get_test_plugin_version(): array
- Since
- 5.2.0
- Source
wp-admin/includes/class-wp-site-health.php:355
Description
The test checks if your plugins are up to date, and encourages you to remove any that are not in use.
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_plugin_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
- 62–136
- 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 183.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Site_Health::get_test_plugin_version() - cacheobject cache
wp_cache_get()one call below WP_Site_Health::get_test_plugin_version() - transienttransient
get_site_transient()one call below WP_Site_Health::get_test_plugin_version() - optionoption read or write
get_option()one call below WP_Site_Health::get_test_plugin_version()
Further down the call graph this can also reach 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 · 9 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_plugin_version() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$plugins_need_update && !$plugins_active | 62–64 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), __() |
!$plugins_need_update && $plugins_active && is_multisite() | 65–67 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), __(), is_multisite() |
!$plugins_need_update && $plugins_active !== 1 | 70–71 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), _n(), sprintf() |
!$plugins_need_update && $plugins_active !== 1 && $plugins_active && is_multisite() | 73–74 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), _n(), sprintf(), is_multisite() |
$plugins_need_update && !$plugins_active | 89–90 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), __(), _n(), sprintf(), network_admin_url(), esc_url(), __() |
$plugins_need_update && $plugins_active && is_multisite() | 92–93 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), __(), _n(), sprintf(), network_admin_url(), esc_url(), __(), is_multisite() |
!$plugins_need_update && $plugins_active && !is_multisite() | 108–110 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), __(), is_multisite(), __(), _n(), sprintf(), __(), admin_url(), esc_url(), __() |
!$plugins_need_update && $plugins_active !== 1 && $plugins_active && !is_multisite() | 116–117 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), _n(), sprintf(), is_multisite(), __(), _n(), sprintf(), __(), admin_url(), esc_url(), __() |
$plugins_need_update && $plugins_active && !is_multisite() | 135–136 | __(), __(), __(), admin_url(), esc_url(), __(), get_plugins(), get_plugin_updates(), __(), _n(), sprintf(), network_admin_url(), esc_url(), __(), is_multisite(), __(), _n(), sprintf(), __(), admin_url(), esc_url(), __() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 183 | 62–136 | 9 | |
| 8.5 | 183 | 62–136 | 9 | |
| 8.4 | 183 | 62–136 | 9 | 5 fewer instructions than PHP 8.3 |
| 8.3 | 188 | 64–138 | 9 | |
| 8.2 | 188 | 64–138 | 9 | |
| 8.1 | 188 | 64–138 | 9 | |
| 7.4 | 188 | 64–138 | 9 |
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 · 9
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- admin_url()Retrieves the URL to the admin area for the current site.
- get_plugins()Checks the plugins directory and retrieve all plugin files with plugin data.
- get_plugin_updates()Retrieves plugins with updates available.
- is_plugin_active()Determines whether a plugin is active.
- _n()Translates and retrieves the singular or plural form based on the supplied number.
- network_admin_url()Retrieves the URL to the admin area for the network.
- is_multisite()Determines whether Multisite is enabled.
Source code
public function get_test_plugin_version() { $result = array( 'label' => __( 'Your plugins are all up to date' ), 'status' => 'good', 'badge' => array( 'label' => __( 'Security' ), 'color' => 'blue', ), 'description' => sprintf( '<p>%s</p>', __( 'Plugins extend your site’s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it’s vital to keep them up to date.' ) ), 'actions' => sprintf( '<p><a href="%s">%s</a></p>', esc_url( admin_url( 'plugins.php' ) ), __( 'Manage your plugins' ) ), 'test' => 'plugin_version', ); $plugins = get_plugins(); $plugin_updates = get_plugin_updates(); $plugins_active = 0; $plugins_total = 0; $plugins_need_update = 0; // Loop over the available plugins and check their versions and active state. foreach ( $plugins as $plugin_path => $plugin ) { ++$plugins_total; if ( is_plugin_active( $plugin_path ) ) { ++$plugins_active; } if ( array_key_exists( $plugin_path, $plugin_updates ) ) { ++$plugins_need_update; } } // Add a notice if there are outdated plugins. if ( $plugins_need_update > 0 ) { $result['status'] = 'critical'; $result['label'] = __( 'You have plugins waiting to be updated' ); $result['description'] .= sprintf( '<p>%s</p>', sprintf( /* translators: %d: The number of outdated plugins. */ _n( 'Your site has %d plugin waiting to be updated.', 'Your site has %d plugins waiting to be updated.', $plugins_need_update ), $plugins_need_update ) ); $result['actions'] .= sprintf( '<p><a href="%s">%s</a></p>', esc_url( network_admin_url( 'plugins.php?plugin_status=upgrade' ) ), __( 'Update your plugins' ) ); } else { if ( 1 === $plugins_active ) { $result['description'] .= sprintf( '<p>%s</p>', __( 'Your site has 1 active plugin, and it is up to date.' ) ); } elseif ( $plugins_active > 0 ) { $result['description'] .= sprintf( '<p>%s</p>', sprintf( /* translators: %d: The number of active plugins. */ _n( 'Your site has %d active plugin, and it is up to date.', 'Your site has %d active plugins, and they are all up to date.', $plugins_active ),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 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.