Last active
January 2, 2018 10:21
-
-
Save jamesmorrison/40b6e5db1f98057a7138fba95b7a7e5e to your computer and use it in GitHub Desktop.
Disable one or more network active plugins for one or more sites
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'site_option_active_sitewide_plugins', | |
function( $value ) { | |
// Lookup the current site object global | |
$current_blog; | |
// This would disable the plugins on sites with ID's 2, 3 and 5 | |
if ( in_array( $current_blog->blog_id, [ 2, 3, 5 ] ) ) { | |
// Loop through each plugin that needs to be disabled | |
foreach ( [ 'akismet/akismet.php', 'other/plugin.php' ] as $plugin ) { | |
// Ensure the plugin is active, we can't disable it if it's not active.. | |
if ( array_key_exists( $plugin ) ) { | |
unset( $value[ $plugin ] ); | |
} | |
} | |
} | |
return $value; | |
}, | |
10 ,1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment