4/5/2012 - 1:06 PM

Automatically enable plugins in new WordPress Multisite blogs

Automatically enable plugins in new WordPress Multisite blogs

There are three options (that I know of) for automatically enabling a plugin in new sites.

  1. Move the plugin from wp-content/plugins/ to wp-content/mu-plugins/ (MU = Must Use). But then it cannot be deactivated for any site.

  2. Click Network Activate instead of Activate to enable it for all sites. I didn't want to use this though because I didn't want to affect existing sites. Also I couldn't work out how to deactivate it for some sites (although I've read this should be possible).

  3. Write a plugin (in wp-content/mu-plugins/) with a hook that activates the plugin at creation time. This way it only affects new blogs, can be deactivated easily, and I can also set the default configuration at the same time.


// Helper to activate a plugin on another site without causing a fatal error by
// including the plugin file a second time
// Based on activate_plugin() in wp-admin/includes/plugin.php
// $buffer option is used for All in One SEO Pack, which sends output otherwise
function djm_activate_plugin($plugin, $buffer = false)
    $current = get_option('active_plugins', array());
    if (!in_array($plugin, $current)) {
        if ($buffer) {
        include_once(WP_PLUGIN_DIR . '/' . $plugin);
        do_action('activate_plugin', $plugin);
        do_action('activate_' . $plugin);
        $current[] = $plugin;
        update_option('active_plugins', $current);
        do_action('activated_plugin', $plugin);
        if ($buffer) {

add_action('wpmu_new_blog', 'djm_wpmu_new_blog', 12, 6); // includes/ms-functions.php
function djm_wpmu_new_blog($blog_id, $user_id, $domain, $path, $site_id, $meta)
    // Activate All in One SEO Pack
    djm_activate_plugin('all-in-one-seo-pack/all_in_one_seo_pack.php', true);
    // Configure All in One SEO Pack
    $options = get_option('aioseop_options', array());
    $options['aiosp_enabled'] = '1';
    $options['aiosp_paged_format'] = ' - Page %page%';
    $options['aiosp_cap_cats'] = '0';
    update_option('aioseop_options', $options);