How to disable a network enabled plugin for just one site?

I’m in the process of setting up a (potentially) large multisite network, and I’m looking to make it as easy as possible now to add and configure sites when needed. I’m currently at the phase where I’m dealing with plugins.

With multisite I am aware of several different ways you can activate plugins

  • Put the plugin in /plugins, activate it on every site invidually
  • Put the plugin in /plugins, use ‘network activate’ to activate it on all sites
  • Put the plugin in /mu-plugins, automatically activated on every site

Now, I’ve been playing with the settings and I want to activate Akismet on all sites but one or two. I thought I would be able to network activate the plugin and then disable it on a single site, but I am unable to do so – if I use network activate then there is only the option to ‘network deactivate’ – which deactivates the plugin across all sites.

Is there a way to have the handy functionality of network activate but yet still have the convenience of being able to deactivate plugins on a site-by-site basis?

8

You can use the filter site_option_*.

E.g. the following will disable akismet on blog with id 2.

add_filter('site_option_active_sitewide_plugins', 'modify_sitewide_plugins');

function modify_sitewide_plugins($value) {
    global $current_blog;

    if( $current_blog->blog_id == 2 ) {
        unset($value['akismet/akismet.php']);
    }

    return $value;
}

Leave a Comment