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
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: trueWhether 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
- Scaling
- Scales with input
- Instructions
- 46–188
- 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 280.
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 Plugin_Upgrader::bulk_upgrade() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 46 | wp_get_wp_version(), wp_parse_args(), ->init(), ->upgrade_strings(), get_site_transient(), ->header(), ->footer() |
| always | 103–108 | wp_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() |
| always | 106–111 | wp_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 === false | 166–170 | wp_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 === false | 168–172 | wp_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 === false | 169–173 | wp_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 === false | 169–173 | wp_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 === false | 171–175 | wp_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 === false | 172–176 | wp_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 === false | 174–178 | wp_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 === false | 175–179 | wp_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 === false | 175–179 | wp_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 === false | 177–181 | wp_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 === false | 178–182 | wp_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 === false | 178–182 | wp_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 === false | 181–185 | wp_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 === false | 184–188 | wp_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 280 | 46–188 | 20 | |
| 8.5 | 280 | 46–188 | 20 | |
| 8.4 | 280 | 46–188 | 20 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 282 | 46–190 | 20 | |
| 8.2 | 282 | 46–190 | 20 | |
| 8.1 | 282 | 46–190 | 20 | |
| 7.4 | 282 | 46–190 | 20 |
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:
- do_action( upgrader_process_complete )actionline 412 (+127 into the body)
Fires when the upgrader process is complete.
Uses · 22
- 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.
- is_plugin_active()Determines whether a plugin is active.
- get_plugin_data()Parses the plugin contents to retrieve plugin's metadata.
- 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.
- remove_filter()Removes a callback function from a filter hook.
- wp_clean_plugins_cache()Clears the plugins cache used by get_plugins() and by default, the plugin updates cache.
Show all 22
- 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.
- Plugin_Upgrader::init()
- Plugin_Upgrader::upgrade_strings()Initializes the upgrade strings.
- Plugin_Upgrader::fs_connect()
- Plugin_Upgrader::maintenance_mode()
- WP_Error::__construct()Initializes the error.
- Plugin_Upgrader::run()
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.
Signature, return type and hooks compared across 5 parsed releases.
$args parameter was added, making clearing the plugin update cache optional.from the docblockAbout 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.