wppaste
WordPress

Plugin_Upgrader::bulk_upgrade( string[] $plugins, array $args = array() ): array|false

Since
2.8.0, 3.7.0
Source
wp-admin/includes/class-plugin-upgrader.php:285
Upgrades several plugins at once.

Compatibility

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

$pluginsstring[]
Array of paths to plugin files relative to the plugins directory.
$argsarrayoptional
Other arguments for upgrading several plugins at once.Default: array()
  • $clear_update_cachebooldefault: true

    Whether to clear the plugin updates cache if successful.

Return value

array|false
An array of results indexed by plugin file, or false if unable to connect to the filesystem.

Performance profile

How much work a call to Plugin_Upgrader::bulk_upgrade() 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 what you pass in.

Instructions
46–188

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

Plugin surface
1 hook

Third-party callbacks on 'upgrader_process_complete' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • transienttransientget_site_transient()called directly
  • hookthird-party callbacksdo_action()called directly
  • optionoption read or writeget_option()called directly
  • cacheobject cachewp_cache_get()one call below Plugin_Upgrader::bulk_upgrade()
  • serializeserialisationmaybe_unserialize()one call below Plugin_Upgrader::bulk_upgrade()

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 · 17 distinct outcomes

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

WhenInstructionsCalls it makes
always46wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->footer()
always103–108wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
always106–111wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && isset($upgrade_data) && !is_wp_version_compatible() && $result === false166–170wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), __(), sprintf(), ->fs_connect(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && !is_php_version_compatible() && $result === false168–172wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), get_plugin_data(), is_plugin_active(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && !isset($upgrade_data) && $result === false169–173wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), get_plugin_data(), is_plugin_active(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && isset($upgrade_data) && !is_wp_version_compatible() && $result === false169–173wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), __(), sprintf(), ->fs_connect(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && !is_php_version_compatible() && $result === false171–175wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), get_plugin_data(), is_plugin_active(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && !isset($upgrade_data) && $result === false172–176wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), get_plugin_data(), is_plugin_active(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && isset($upgrade_data) && is_wp_version_compatible() && !is_php_version_compatible() && $result === false174–178wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && is_php_version_compatible() && $result === false175–179wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), get_plugin_data(), is_plugin_active(), is_php_version_compatible(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && is_wp_version_compatible() && $result === false175–179wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
5 further outcomes, up to 188 instructions
!$plugins && isset($plugin) && isset($upgrade_data) && is_wp_version_compatible() && !is_php_version_compatible() && $result === false177–181wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && is_php_version_compatible() && $result === false178–182wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), get_plugin_data(), is_plugin_active(), is_php_version_compatible(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && is_wp_version_compatible() && $result === false178–182wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && isset($upgrade_data) && is_wp_version_compatible() && is_php_version_compatible() && $result === false181–185wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), is_php_version_compatible(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$plugins && isset($plugin) && isset($upgrade_data) && is_wp_version_compatible() && is_php_version_compatible() && $result === false184–188wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), get_plugin_data(), is_plugin_active(), is_wp_version_compatible(), is_php_version_compatible(), slug(), ->maintenance_mode(), wp_clean_plugins_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev28046–18820
8.528046–18820
8.428046–188202 fewer instructions than PHP 8.3
8.328246–19020
8.228246–19020
8.128246–19020
7.428246–19020

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

One hook fires while Plugin_Upgrader::bulk_upgrade() runs, in this order:

  1. do_action( upgrader_process_complete )actionline 412 (+127 into the body)

    Fires when the upgrader process is complete.

Uses · 22

Show all 22

Source code

	public function bulk_upgrade( $plugins, $args = array() ) {		$wp_version = wp_get_wp_version(); 		$defaults    = array(			'clear_update_cache' => true,		);		$parsed_args = wp_parse_args( $args, $defaults ); 		$this->init();		$this->bulk = true;		$this->upgrade_strings(); 		$current = get_site_transient( 'update_plugins' ); 		add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_plugin' ), 10, 4 ); 		$this->skin->header(); 		// Connect to the filesystem first.		$connected = $this->fs_connect( array( WP_CONTENT_DIR, WP_PLUGIN_DIR ) );		if ( ! $connected ) {			$this->skin->footer();			return false;		} 		$this->skin->bulk_header(); 		/*		 * Only start maintenance mode if:		 * - running Multisite and there are one or more plugins specified, OR		 * - a plugin with an update available is currently active.		 * @todo For multisite, maintenance mode should only kick in for individual sites if at all possible.		 */		$maintenance = ( is_multisite() && ! empty( $plugins ) );		foreach ( $plugins as $plugin ) {			$maintenance = $maintenance || ( is_plugin_active( $plugin ) && isset( $current->response[ $plugin ] ) );		}		if ( $maintenance ) {			$this->maintenance_mode( true );		} 		$results = array(); 		$this->update_count   = count( $plugins );		$this->update_current = 0;		foreach ( $plugins as $plugin ) {			++$this->update_current;			$this->skin->plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin, false, true ); 			if ( ! isset( $current->response[ $plugin ] ) ) {				$this->skin->set_result( 'up_to_date' );				$this->skin->before();				$this->skin->feedback( 'up_to_date' );				$this->skin->after();				$results[ $plugin ] = true;				continue;			} 			// Get the URL to the zip file.			$upgrade_data = $current->response[ $plugin ]; 			$this->skin->plugin_active = is_plugin_active( $plugin ); 			if ( isset( $upgrade_data->requires ) && ! is_wp_version_compatible( $upgrade_data->requires ) ) {				$result = new WP_Error(					'incompatible_wp_required_version',					sprintf(						/* translators: 1: Current WordPress version, 2: WordPress version required by the new plugin version. */						__( 'Your WordPress version is %1$s, however the new plugin version requires %2$s.' ),						$wp_version,						$upgrade_data->requires					)				); 				$this->skin->before( $result );				$this->skin->error( $result );				$this->skin->after();			} elseif ( isset( $upgrade_data->requires_php ) && ! is_php_version_compatible( $upgrade_data->requires_php ) ) {				$result = new WP_Error(					'incompatible_php_required_version',

Changelog

Introduced in 2.8.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.

3.7.0
The $args parameter was added, making clearing the plugin update cache optional.from the docblock
2.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-admin/includes/class-plugin-upgrader.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.