wppaste
WordPress

deactivate_plugins( string|string[] $plugins, bool $silent = false, bool|null $network_wide = null )

Since
2.5.0
Source
wp-admin/includes/plugin.php:758
Deactivates a single plugin or multiple plugins.

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

Reads stored settings via get_site_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
19–33

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

Plugin surface
3 hooks

Third-party callbacks on 'deactivate_plugin', 'deactivate_{$plugin}', 'deactivated_plugin' run inside this call, and their cost is not bounded by anything here.

Called by
6

6 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionnetwork optionget_site_option()called directly
  • hookthird-party callbacksdo_action()called directly
  • cacheobject cachewp_cache_get()one call below deactivate_plugins()
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
!is_multisite()19–20is_multisite(), get_option()
!is_multisite()23–24is_multisite(), get_option(), update_site_option()
!is_multisite()23–24is_multisite(), get_option(), update_option()
is_multisite()24–25is_multisite(), get_site_option(), get_option()
!is_multisite()27–28is_multisite(), get_option(), update_option(), update_site_option()
is_multisite()28–29is_multisite(), get_site_option(), get_option(), update_site_option()
is_multisite()28–29is_multisite(), get_site_option(), get_option(), update_option()
is_multisite()32–33is_multisite(), get_site_option(), get_option(), update_option(), update_site_option()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev10519–3316
8.510519–3316
8.410519–33162 fewer instructions than PHP 8.3
8.310719–3316
8.210719–3316
8.110719–3316
7.410719–3316

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:

  1. do_action( deactivate_plugin )actionline 787 (+29 into the body)

    Fires before a plugin is deactivated.

  2. do_action( deactivate_{$plugin} )actionline 826 (+68 into the body)

    Fires before a plugin is deactivated.

  3. do_action( deactivated_plugin )actionline 840 (+82 into the body)

    Fires after a plugin is deactivated.

Uses · 12

Used by · 6

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 network

Changelog

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

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 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.