Instantly share code, notes, and snippets.

Embed
What would you like to do?
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