wppaste
WordPress

Theme_Upgrader::bulk_upgrade( string[] $themes, array $args = array() ): array[]|false

Since
3.0.0, 3.7.0
Source
wp-admin/includes/class-theme-upgrader.php:383
Upgrades several themes 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

$themesstring[]
Array of the theme slugs.
$argsarrayoptional
Other arguments for upgrading several themes at once. Default empty array.Default: array()
  • $clear_update_cachebooldefault: true

    Whether to clear the update cache if successful.

Return value

array[]|false
An array of results, or false if unable to connect to the filesystem.

Performance profile

How much work a call to Theme_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
62–210

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

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 Theme_Upgrader::bulk_upgrade()
  • serializeserialisationmaybe_unserialize()one call below Theme_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 Theme_Upgrader::bulk_upgrade() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always62wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->footer()
always133–138wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
always136–141wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && isset($upgrade_data) && !is_wp_version_compatible() && $result === false185–189wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->theme_info(), is_wp_version_compatible(), __(), sprintf(), ->fs_connect(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && !is_php_version_compatible() && $result === false187–191wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->theme_info(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && isset($upgrade_data) && !is_wp_version_compatible() && $result === false188–192wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->theme_info(), is_wp_version_compatible(), __(), sprintf(), ->fs_connect(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && !is_php_version_compatible() && $result === false190–194wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->theme_info(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && !isset($upgrade_data) && $result === false191–195wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->theme_info(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && isset($upgrade_data) && is_wp_version_compatible() && !is_php_version_compatible() && $result === false193–197wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->theme_info(), is_wp_version_compatible(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && !isset($upgrade_data) && $result === false194–198wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->theme_info(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && isset($upgrade_data) && is_wp_version_compatible() && !is_php_version_compatible() && $result === false196–200wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->theme_info(), is_wp_version_compatible(), is_php_version_compatible(), __(), sprintf(), add_filter(), ->before(), ->error(), ->after(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && is_php_version_compatible() && $result === false197–201wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->theme_info(), is_php_version_compatible(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
5 further outcomes, up to 210 instructions
!$themes && isset($theme) && is_wp_version_compatible() && $result === false197–201wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->theme_info(), is_wp_version_compatible(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && is_php_version_compatible() && $result === false200–204wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->theme_info(), is_php_version_compatible(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && is_wp_version_compatible() && $result === false200–204wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->theme_info(), is_wp_version_compatible(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && isset($upgrade_data) && is_wp_version_compatible() && is_php_version_compatible() && $result === false203–207wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->theme_info(), is_wp_version_compatible(), is_php_version_compatible(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()
!$themes && isset($theme) && isset($upgrade_data) && is_wp_version_compatible() && is_php_version_compatible() && $result === false206–210wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->bulk_header(), is_multisite(), ->maintenance_mode(), ->theme_info(), is_wp_version_compatible(), is_php_version_compatible(), get_theme_root(), get_theme_root(), slug(), ->maintenance_mode(), wp_clean_themes_cache(), update(), ->bulk_footer(), ->footer(), get_option(), update_option()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 303 instructions, 62–210 executed per call, 20 branches. The work does not change between versions.

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 Theme_Upgrader::bulk_upgrade() runs, in this order:

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

    Fires when the upgrader process is complete.

Uses · 24

Show all 24

Source code

	public function bulk_upgrade( $themes, $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_themes' ); 		add_filter( 'upgrader_pre_install', array( $this, 'current_before' ), 10, 2 );		add_filter( 'upgrader_post_install', array( $this, 'current_after' ), 10, 2 );		add_filter( 'upgrader_clear_destination', array( $this, 'delete_old_theme' ), 10, 4 ); 		$this->skin->header(); 		// Connect to the filesystem first.		$connected = $this->fs_connect( array( WP_CONTENT_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 themes specified, OR		 * - a theme with an update available is currently in use.		 * @todo For multisite, maintenance mode should only kick in for individual sites if at all possible.		 */		$maintenance = ( is_multisite() && ! empty( $themes ) );		foreach ( $themes as $theme ) {			$maintenance = $maintenance || get_stylesheet() === $theme || get_template() === $theme;		}		if ( $maintenance ) {			$this->maintenance_mode( true );		} 		$results = array(); 		$this->update_count   = count( $themes );		$this->update_current = 0;		foreach ( $themes as $theme ) {			++$this->update_current; 			$this->skin->theme_info = $this->theme_info( $theme ); 			if ( ! isset( $current->response[ $theme ] ) ) {				$this->skin->set_result( true );				$this->skin->before();				$this->skin->feedback( 'up_to_date' );				$this->skin->after();				$results[ $theme ] = true;				continue;			} 			// Get the URL to the zip file.			$upgrade_data = $current->response[ $theme ]; 			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 theme version. */						__( 'Your WordPress version is %1$s, however the new theme 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 3.0.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 update cache optional.from the docblock
3.0.0
Introduced.from the docblock

About this page

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