wppaste
WordPress

WP_Site_Health::get_test_plugin_version(): array

Since
5.2.0
Source
wp-admin/includes/class-wp-site-health.php:355
Tests if plugins are outdated, or unnecessary.

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

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
62–136

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

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

  • hookthird-party callbacksapply_filters()one call below WP_Site_Health::get_test_plugin_version()
  • cacheobject cachewp_cache_get()one call below WP_Site_Health::get_test_plugin_version()
  • transienttransientget_site_transient()one call below WP_Site_Health::get_test_plugin_version()
  • optionoption read or writeget_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.

WhenInstructionsCalls it makes
!$plugins_need_update && !$plugins_active62–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 !== 170–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_active89–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

PHPCompiledExecutedBranchesNotes
8.6-dev18362–1369
8.518362–1369
8.418362–13695 fewer instructions than PHP 8.3
8.318864–1389
8.218864–1389
8.118864–1389
7.418864–1389

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

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&#8217;s functionality with things like contact forms, ecommerce and much more. That means they have deep access to your site, so it&#8217;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.

  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 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.