wppaste
WordPress

wp_update_plugins( array $extra_stats = array() )

Since
2.3.0
Source
wp-includes/update.php:315
Checks for available updates to plugins based on the latest versions hosted on WordPress.org.

Description

Despite its name this function does not actually perform any updates, it only checks for available updates.

A list of all plugins installed is sent to WP, along with the site locale.

Checks against the WordPress server at api.wordpress.org. Will only check if WordPress isn't installing.

Compatibility

WordPress
since 2.3.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.

Parameters

$extra_statsarrayoptional
Extra statistics to report to the WordPress.org API.Default: array()

Performance profile

How much work a call to wp_update_plugins() 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
Expensive

Reaches an outbound HTTP request via wp_remote_post().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
6

Executed per call on PHP 8.5. The body compiles to 389.

Plugin surface
2 hooks

Third-party callbacks on 'plugins_update_check_locales', 'update_plugins_{$hostname}' run inside this call, and their cost is not bounded by anything here.

Called by
5

5 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • transienttransientget_site_transient()called directly
  • hookthird-party callbacksapply_filters()called directly
  • httpoutbound HTTP requestwp_remote_post()called directly
  • cacheobject cachewp_cache_get()one call below wp_update_plugins()
  • serializeserialisationmaybe_unserialize()one call below wp_update_plugins()

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 · 1 distinct outcome

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

WhenInstructionsCalls it makes
always6none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev389647
8.5389647
8.4389647
8.3389647
8.23896471 more instruction than PHP 8.1
8.13886472 fewer instructions than PHP 7.4
7.4390647

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.

Hooks and filters fired · 2

2 hooks fire while wp_update_plugins() runs, in this order:

  1. apply_filters( plugins_update_check_locales )filterline 407 (+92 into the body)

    Filters the locales requested for plugin translations.

  2. apply_filters( update_plugins_{$hostname} )filterline 514 (+199 into the body)

    Filters the update response for a given plugin hostname.

Uses · 24

Show all 24

Used by · 5

Source code

function wp_update_plugins( $extra_stats = array() ) {	if ( wp_installing() ) {		return;	} 	// If running blog-side, bail unless we've not checked in the last 12 hours.	if ( ! function_exists( 'get_plugins' ) ) {		require_once ABSPATH . 'wp-admin/includes/plugin.php';	} 	$plugins      = get_plugins();	$translations = wp_get_installed_translations( 'plugins' ); 	$active  = get_option( 'active_plugins', array() );	$current = get_site_transient( 'update_plugins' ); 	if ( ! is_object( $current ) ) {		$current = new stdClass();	} 	$updates               = new stdClass();	$updates->last_checked = time();	$updates->response     = array();	$updates->translations = array();	$updates->no_update    = array(); 	$doing_cron = wp_doing_cron(); 	// Check for update on a different schedule, depending on the page.	switch ( current_filter() ) {		case 'upgrader_process_complete':			$timeout = 0;			break;		case 'load-update-core.php':			$timeout = MINUTE_IN_SECONDS;			break;		case 'load-plugins.php':		case 'load-update.php':			$timeout = HOUR_IN_SECONDS;			break;		default:			if ( $doing_cron ) {				$timeout = 2 * HOUR_IN_SECONDS;			} else {				$timeout = 12 * HOUR_IN_SECONDS;			}	} 	$time_not_changed = isset( $current->last_checked ) && $timeout > ( time() - $current->last_checked ); 	if ( $time_not_changed && ! $extra_stats ) {		$plugin_changed = false; 		foreach ( $plugins as $file => $p ) {			$updates->checked[ $file ] = $p['Version']; 			if ( ! isset( $current->checked[ $file ] ) || (string) $current->checked[ $file ] !== (string) $p['Version'] ) {				$plugin_changed = true;			}		} 		if ( isset( $current->response ) && is_array( $current->response ) ) {			foreach ( $current->response as $plugin_file => $update_details ) {				if ( ! isset( $plugins[ $plugin_file ] ) ) {					$plugin_changed = true;					break;				}			}		} 		// Bail if we've checked recently and if nothing has changed.		if ( ! $plugin_changed ) {			return;		}	} 	// Update last_checked for current to prevent multiple blocking requests if request hangs.	$current->last_checked = time();	set_site_transient( 'update_plugins', $current );

Changelog

Introduced in 2.3.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.7.7 tag, from src/wp-includes/update.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.