Skip to content

Instantly share code, notes, and snippets.

@jamesmorrison
Last active January 2, 2018 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesmorrison/40b6e5db1f98057a7138fba95b7a7e5e to your computer and use it in GitHub Desktop.
Save jamesmorrison/40b6e5db1f98057a7138fba95b7a7e5e to your computer and use it in GitHub Desktop.
Disable one or more network active plugins for one or more sites
<?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