Using WordPress ‘deactivate_sitewide_plugin()’ PHP function

The deactivate_sitewide_plugin() WordPress PHP function is a deprecated function that was once used for deactivating a network-only plugin. It’s advisable to use the deactivate_plugin() function instead.

Usage

Here’s a generic example of how this function was used:

deactivate_sitewide_plugin('plugin-directory/plugin-file.php');

This line of code would deactivate a network-wide plugin with the directory and file name ‘plugin-directory/plugin-file.php’.

Parameters

  • This function does not accept any parameters.

More information

See WordPress Developer Resources: deactivate_sitewide_plugin()

The deactivate_sitewide_plugin() function was deprecated in WordPress 3.1.0. It’s suggested to use deactivate_plugin() instead.

Examples

Deactivating a plugin network-wide

Here’s how you could have used this function to deactivate a plugin across your entire network:

// If the 'example-plugin' is active network-wide
if (is_plugin_active_for_network('example-plugin/example-plugin.php')) {
    // Deactivate it
    deactivate_sitewide_plugin('example-plugin/example-plugin.php');
}

This code checks if ‘example-plugin’ is active network-wide. If it is, the code deactivates it.

Using deactivate_plugin() instead

Since deactivate_sitewide_plugin() is deprecated, you should use deactivate_plugin(). Here’s how you can use it to achieve the same result:

// If the 'example-plugin' is active network-wide
if (is_plugin_active_for_network('example-plugin/example-plugin.php')) {
    // Deactivate it
    deactivate_plugin('example-plugin/example-plugin.php', true);
}

This code checks if ‘example-plugin’ is active network-wide. If it is, the code deactivates it using deactivate_plugin() with the second parameter set to true for network-wide deactivation.