2

I have setup a WP MU site and installed a plugin into the main MU site. I want this plugin enabled across all the sites and hidden from site admins if possible. I want the plugin settings to come from the super network site not site admins. On my super admin plugins page I see this:

enter image description here

Notice the Network Activate link. I enabled it but new sites do not have the settings from the main site and the plug in is not hidden (it not as important if it's hidden or not).

1

For the activation of your plugin you have to write few lines of code in the plugin.

The WordPress installation runs from wp-admin/install.php. What we are looking for is for certain actions to be triggered once the install is successful, so a good place to insert our code is right above this:

<h1><?php _e( 'Success!' ); ?></h1>

We see a code block that starts with:

if ( $error === false ) {
$wpdb->show_errors();
$result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password);
extract( $result, EXTR_SKIP );

I chose to insert our actions after the last extract statement. To activate the plugins, I added:

require_once( dirname( dirname( __FILE__ ) ) . '/wp-admin/includes/plugin.php' );
activate_plugin( dirname( dirname( __FILE__ ) ) . '/wp-content/plugins/plugin-dir-name/pluginfile.php' );

And for the hiding the plugin from the list of plugin:

/**
 * Filter the list of plugins according to user_login
 *
 * Usage: configure the variable $plugin_credentials, which holds a list of users and their plugins.
 * To give full access, put a simple string "ALL"
 * To grant only for some plugins, create an array with the Plugin Slug, 
 *    which is the file name without extension (akismet.php, hello.php)
 *
 * @return array List of plugins
 */
function wdm_plugin_permissions( $plugins )
{
    // Config
    $plugin_credentials = array(
        'admin' => "ALL",
        'other-admin' => array(
            'akismet',
        ),
        'another-admin' => array(
            'akismet',
            'hello',
        ),
    );

    // Current user
    global $current_user;
    $username = $current_user->user_login;

    // Super admin, return everything
    if ( "ALL" == $plugin_credentials[ $username ] )
        return $plugins;

    // Filter the plugins of the user
    foreach ( $plugins as $key => $value ) 
    { 
        // Get the file name minus extension
        $plugin_slug = basename( $key, '.php' );

        // If not in the list of allowed plugins, remove from array
        if( !in_array( $plugin_slug, $plugin_credentials[ $username ] ) )
            unset( $plugins[ $key ] );
    }

    return $plugins;
}
add_filter( 'all_plugins', 'wdm_plugin_permissions' );

You need to modify the code as per your users roles.

For plugin hide code you may refer to this

  • Does wp-admin/install.php install the new blog for the user then? Is that where we place the code or is there some code that we place in the plugin? – 1.21 gigawatts Feb 8 '14 at 0:15
  • Using this code you need to create on plugin and then place that file in your plugins directory – WisdmLabs Feb 13 '14 at 10:19
  • This is great and I will need to do this soon but I did not mention I am using a preexisting plugin. I did not create it. In WP MU there is a Network Activate link. I have enabled the plugin site wide by enabling that. But, new blogs are created with the plugin but it's settings are default and not the settings I am using as super admin. – 1.21 gigawatts Feb 13 '14 at 13:58
  • I've updated the question. – 1.21 gigawatts Feb 13 '14 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.