deactivate_plugins( string|string[] $plugins, bool $silent = false, bool|null $network_wide = null )
- Since
- 2.5.0
- Source
wp-admin/includes/plugin.php:758
Description
The deactivation hook is disabled by the plugin upgrader by using the $silent parameter.
Compatibility
- WordPress
- since 2.5.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|string[]- Single plugin or list of plugins to deactivate.
$silentbooloptional- Prevent calling deactivation hooks. Default false.Default:
false $network_widebool|nulloptional- Whether to deactivate the plugin for all sites in the network.
A value of null will deactivate plugins for both the network and the current site. Multisite only. Default null.Default:null
Performance profile
How much work a call to deactivate_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
- Heavy
- Scaling
- Scales with input
- Instructions
- 19–33
- Plugin surface
- 3 hooks
- Called by
- 6
Reads stored settings via get_site_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 105.
Third-party callbacks on 'deactivate_plugin', 'deactivate_{$plugin}', 'deactivated_plugin' run inside this call, and their cost is not bounded by anything here.
6 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionnetwork option
get_site_option()called directly - hookthird-party callbacks
do_action()called directly - cacheobject cache
wp_cache_get()one call below deactivate_plugins() - serializeserialisation
maybe_unserialize()one call below deactivate_plugins()
Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost deactivate_plugins() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_multisite() | 19–20 | is_multisite(), get_option() |
!is_multisite() | 23–24 | is_multisite(), get_option(), update_site_option() |
!is_multisite() | 23–24 | is_multisite(), get_option(), update_option() |
is_multisite() | 24–25 | is_multisite(), get_site_option(), get_option() |
!is_multisite() | 27–28 | is_multisite(), get_option(), update_option(), update_site_option() |
is_multisite() | 28–29 | is_multisite(), get_site_option(), get_option(), update_site_option() |
is_multisite() | 28–29 | is_multisite(), get_site_option(), get_option(), update_option() |
is_multisite() | 32–33 | is_multisite(), get_site_option(), get_option(), update_option(), update_site_option() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 105 | 19–33 | 16 | |
| 8.5 | 105 | 19–33 | 16 | |
| 8.4 | 105 | 19–33 | 16 | 2 fewer instructions than PHP 8.3 |
| 8.3 | 107 | 19–33 | 16 | |
| 8.2 | 107 | 19–33 | 16 | |
| 8.1 | 107 | 19–33 | 16 | |
| 7.4 | 107 | 19–33 | 16 |
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 · 3
3 hooks fire while deactivate_plugins() runs, in this order:
- do_action( deactivate_plugin )actionline 787 (+29 into the body)
Fires before a plugin is deactivated.
- do_action( deactivate_{$plugin} )actionline 826 (+68 into the body)
Fires before a plugin is deactivated.
- do_action( deactivated_plugin )actionline 840 (+82 into the body)
Fires after a plugin is deactivated.
Uses · 12
- is_multisite()Determines whether Multisite is enabled.
- get_site_option()Retrieve an option value for the current network based on name of option.
- get_option()Retrieves an option value based on an option name.
- plugin_basename()Gets the basename of a plugin.
- is_plugin_active()Determines whether a plugin is active.
- is_plugin_active_for_network()Determines whether the plugin is active for the entire network.
- do_action()Calls the callback functions that have been added to an action hook.
- wp_is_recovery_mode()Determines whether WordPress is in Recovery Mode.
- wp_paused_plugins()Get the instance for storing paused plugins.
- update_option()Updates the value of an option that was already added.
- update_site_option()Updates the value of an option that was already added for the current network.
- wp_paused_plugins()::delete()
Used by · 6
- Plugin_Upgrader::deactivate_plugin_before_upgrade()Deactivates a plugin before it is upgraded.
- WP_REST_Plugins_Controller::handle_plugin_status()Handle updating a plugin's status.
- _upgrade_440_force_deactivate_incompatible_plugins()
- _upgrade_core_deactivate_incompatible_plugins()
- upgrade_380()Execute changes made in WordPress 3.8.0.
- validate_active_plugins()Validates active plugins.
Source code
function deactivate_plugins( $plugins, $silent = false, $network_wide = null ) { if ( is_multisite() ) { $network_current = get_site_option( 'active_sitewide_plugins', array() ); } $current = get_option( 'active_plugins', array() ); $do_blog = false; $do_network = false; foreach ( (array) $plugins as $plugin ) { $plugin = plugin_basename( trim( $plugin ) ); if ( ! is_plugin_active( $plugin ) ) { continue; } $network_deactivating = ( false !== $network_wide ) && is_plugin_active_for_network( $plugin ); if ( ! $silent ) { /** * Fires before a plugin is deactivated. * * If a plugin is silently deactivated (such as during an update), * this hook does not fire. * * @since 2.9.0 * * @param string $plugin Path to the plugin file relative to the plugins directory. * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network * or just the current site. Multisite only. Default false. */ do_action( 'deactivate_plugin', $plugin, $network_deactivating ); } if ( false !== $network_wide ) { if ( is_plugin_active_for_network( $plugin ) ) { $do_network = true; unset( $network_current[ $plugin ] ); } elseif ( $network_wide ) { continue; } } if ( true !== $network_wide ) { $key = array_search( $plugin, $current, true ); if ( false !== $key ) { $do_blog = true; unset( $current[ $key ] ); } } if ( $do_blog && wp_is_recovery_mode() ) { list( $extension ) = explode( '/', $plugin ); wp_paused_plugins()->delete( $extension ); } if ( ! $silent ) { /** * Fires as a specific plugin is being deactivated. * * This hook is the "deactivation" hook used internally by register_deactivation_hook(). * The dynamic portion of the hook name, `$plugin`, refers to the plugin basename. * * If a plugin is silently deactivated (such as during an update), this hook does not fire. * * @since 2.0.0 * * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the network * or just the current site. Multisite only. Default false. */ do_action( "deactivate_{$plugin}", $network_deactivating ); /** * Fires after a plugin is deactivated. * * If a plugin is silently deactivated (such as during an update), * this hook does not fire. * * @since 2.9.0 * * @param string $plugin Path to the plugin file relative to the plugins directory. * @param bool $network_deactivating Whether the plugin is deactivated for all sites in the networkChangelog
Introduced in 2.5.0. Unchanged from 6.7.7 through 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-admin/includes/plugin.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.