The is_plugin_active_for_network() WordPress PHP function determines whether a plugin is active for the entire network.
Usage
is_plugin_active_for_network('plugin-directory/plugin-file.php');
Parameters
- $plugin (string): Path to the plugin file relative to the plugins directory.
More information
See WordPress Developer Resources: is_plugin_active_for_network
Examples
Check if a plugin is active on the network
This example checks if the “example-plugin” is active for the entire network.
if (is_plugin_active_for_network('example-plugin/example-plugin.php')) {
echo 'The plugin is active on the network.';
} else {
echo 'The plugin is not active on the network.';
}
Display a message on the admin dashboard if the plugin is not network active
This example displays a warning message in the admin dashboard if the “example-plugin” is not active for the entire network.
function warn_if_plugin_not_network_active() {
if (!is_plugin_active_for_network('example-plugin/example-plugin.php')) {
echo '<div class="notice notice-warning is-dismissible">';
echo '<p><strong>Warning:</strong> The Example Plugin is not active on the network!</p>';
echo '</div>';
}
}
add_action('admin_notices', 'warn_if_plugin_not_network_active');
Require a network-active plugin to activate another plugin
This example prevents the “dependent-plugin” from being activated if the “required-plugin” is not active for the entire network.
function require_network_active_plugin($plugin) {
if ($plugin == 'dependent-plugin/dependent-plugin.php' && !is_plugin_active_for_network('required-plugin/required-plugin.php')) {
wp_die('The Required Plugin must be network active to activate the Dependent Plugin.');
}
}
add_action('activated_plugin', 'require_network_active_plugin');
Deactivate a plugin on all sites if it is not network active
This example deactivates the “example-plugin” on all sites in the network if it is not active for the entire network.
function deactivate_plugin_on_all_sites() {
if (!is_plugin_active_for_network('example-plugin/example-plugin.php')) {
$sites = get_sites();
foreach ($sites as $site) {
switch_to_blog($site->blog_id);
deactivate_plugins('example-plugin/example-plugin.php');
restore_current_blog();
}
}
}
add_action('admin_init', 'deactivate_plugin_on_all_sites');
Load a plugin’s admin settings only if it is network active
This example loads the admin settings for the “example-plugin” only if it is active for the entire network.
function load_plugin_admin_settings() {
if (is_plugin_active_for_network('example-plugin/example-plugin.php')) {
include_once 'example-plugin-admin-settings.php';
}
}
add_action('admin_menu', 'load_plugin_admin_settings');