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
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: trueWhether 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
- Scaling
- Scales with input
- Instructions
- 62–210
- Plugin surface
- 1 hook
- 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 what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 303.
Third-party callbacks on 'upgrader_process_complete' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- transienttransient
get_site_transient()called directly - hookthird-party callbacks
do_action()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below Theme_Upgrader::bulk_upgrade() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 62 | wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->footer() |
| always | 133–138 | wp_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() |
| always | 136–141 | wp_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($r) && !is_wp_version_compatible() && $result === false | 185–189 | wp_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 === false | 187–191 | wp_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($r) && !is_wp_version_compatible() && $result === false | 188–192 | wp_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 === false | 190–194 | wp_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($r) && $result === false | 191–195 | wp_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($r) && is_wp_version_compatible() && !is_php_version_compatible() && $result === false | 193–197 | wp_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($r) && $result === false | 194–198 | wp_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($r) && is_wp_version_compatible() && !is_php_version_compatible() && $result === false | 196–200 | wp_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 === false | 197–201 | wp_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 === false | 197–201 | wp_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 === false | 200–204 | wp_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 === false | 200–204 | wp_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($r) && is_wp_version_compatible() && is_php_version_compatible() && $result === false | 203–207 | wp_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($r) && is_wp_version_compatible() && is_php_version_compatible() && $result === false | 206–210 | wp_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:
- do_action( upgrader_process_complete )actionline 510 (+127 into the body)
Fires when the upgrader process is complete.
Uses · 24
- wp_get_wp_version()Returns the current WordPress version.
- wp_parse_args()Merges user defined arguments into defaults array.
- get_site_transient()Retrieves the value of a site transient.
- add_filter()Adds a callback function to a filter hook.
- is_multisite()Determines whether Multisite is enabled.
- get_stylesheet()Retrieves name of the current stylesheet.
- get_template()Retrieves name of the active theme.
- is_wp_version_compatible()Checks compatibility with the current WordPress version.
- __()Retrieves the translation of $text.
- is_php_version_compatible()Checks compatibility with the current PHP version.
- get_theme_root()Retrieves path to themes directory.
- remove_filter()Removes a callback function from a filter hook.
Show all 24
- wp_clean_themes_cache()Clears the cache held by get_theme_roots() and WP_Theme.
- do_action()Calls the callback functions that have been added to an action hook.
- get_option()Retrieves an option value based on an option name.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- update_option()Updates the value of an option that was already added.
- Theme_Upgrader::init()
- Theme_Upgrader::upgrade_strings()Initializes the upgrade strings.
- Theme_Upgrader::fs_connect()
- Theme_Upgrader::maintenance_mode()
- Theme_Upgrader::theme_info()Gets the WP_Theme object for a theme.
- WP_Error::__construct()Initializes the error.
- Theme_Upgrader::run()
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. $res = $this->fs_connect( array( WP_CONTENT_DIR ) ); if ( ! $res ) { $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. $r = $current->response[ $theme ]; if ( isset( $r['requires'] ) && ! is_wp_version_compatible( $r['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, $r['requires'] ) ); $this->skin->before( $result ); $this->skin->error( $result ); $this->skin->after(); } elseif ( isset( $r['requires_php'] ) && ! is_php_version_compatible( $r['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.
Signature, return type and hooks compared across 5 parsed releases.
$args parameter was added, making clearing the update cache optional.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.