Skip to main content
Plugin code update. Update notice.
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264

Update:

  • mu-plugin updated to multiple users and multiple hide plugins was string now it's array

<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/aquestions/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.01
Author: WordPress-StackExchangebrasofilo
AuthorURI: http://wordpress.stackexchange.com/users/12615/
*/

/**
 * Parameters of the class - sorry for the non-standard documentation
 *
 * @super_admin     : stringarray   (required)    : the userusers which isare able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : stringarray   (optional)    : pluginplugins to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow ) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => 'the_user_login'array('Rodolfo','roda'),
            'can_see_mustuse'   => truefalse,
            'can_see_dropins'   => falsetrue,
            'hide_this_one' 'hide_this_ones'    => array( 'set-user-locale.php', 'akismet/akismet.php' )
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user      = $data['super_admin'];
        $this->mustuse  = $data['can_see_mustuse'];
        $this->dropins  = $data['can_see_dropins'];
        $this->hide      = isset($data['hide_this_one'] $data['hide_this_ones'] ) ? $data['hide_this_one']$data['hide_this_ones'] : false;
        
        if($this->hide)
            add_filter( 'all_plugins', array(&$this, 'on_list_plugins' ) );
        
        add_filter( 'show_advanced_plugins', array(&$this, 'on_list_advanced' ), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != in_array( $current_user->user_login, $this->user ) )
            {
    unset            foreach($plugins[$this $this->hide]>hide as $plug )
                    unset( $plugins[$plug] );               
            }

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != in_array( $current_user->user_login, $this->user ) ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}
<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/a/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.0
Author: WordPress-StackExchange
*/

/**
 * Parameters of the class
 *
 * @super_admin     : string  (required)    : the user which is able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : string  (optional)    : plugin to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow ) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => 'the_user_login',
            'can_see_mustuse'   => true,
            'can_see_dropins'   => false,
            'hide_this_one'     => 'akismet/akismet.php'
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user      = $data['super_admin'];
        $this->mustuse  = $data['can_see_mustuse'];
        $this->dropins  = $data['can_see_dropins'];
        $this->hide      = isset($data['hide_this_one']) ? $data['hide_this_one'] : false;
        
        if($this->hide)
            add_filter('all_plugins', array(&$this, 'on_list_plugins') );
        
        add_filter('show_advanced_plugins', array(&$this, 'on_list_advanced'), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != $current_user->user_login ) 
                unset($plugins[$this->hide]);

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != $current_user->user_login ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}

Update:

  • mu-plugin updated to multiple users and multiple hide plugins was string now it's array

<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/questions/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.1
Author: brasofilo
AuthorURI: http://wordpress.stackexchange.com/users/12615/
*/

/**
 * Parameters of the class - sorry for the non-standard documentation
 *
 * @super_admin     : array   (required)    : the users which are able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : array   (optional)    : plugins to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => array('Rodolfo','roda'),
            'can_see_mustuse'   => false,
            'can_see_dropins'   => true,
            'hide_this_ones'    => array( 'set-user-locale.php', 'akismet/akismet.php' )
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user     = $data['super_admin'];
        $this->mustuse  = $data['can_see_mustuse'];
        $this->dropins  = $data['can_see_dropins'];
        $this->hide     = isset( $data['hide_this_ones'] ) ? $data['hide_this_ones'] : false;
        
        if($this->hide)
            add_filter( 'all_plugins', array(&$this, 'on_list_plugins' ) );
        
        add_filter( 'show_advanced_plugins', array(&$this, 'on_list_advanced' ), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( ! in_array( $current_user->user_login, $this->user ) )
            {
                foreach( $this->hide as $plug )
                    unset( $plugins[$plug] );               
            }

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( ! in_array( $current_user->user_login, $this->user ) ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}
The sample user name was wrong (left over from tests). Minor formatting issue.
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264
<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/a/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.0
Author: WordPress-StackExchange
*/

/**
 * Parameters of the class
 *
 * @super_admin     : string  (required)    : the user which is able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : string  (optional)    : plugin to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow ) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => 'roda''the_user_login',
            'can_see_mustuse'   => true,
            'can_see_dropins'   => false,
            'hide_this_one'     => 'akismet/akismet.php'
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user      = $data['super_admin'];
        $this->mustuse  = $data['can_see_mustuse'];
        $this->dropins  = $data['can_see_dropins'];
        $this->hide      = isset($data['hide_this_one']) ? $data['hide_this_one'] : false;
        
        if($this->hide)
            add_filter('all_plugins', array(&$this, 'on_list_plugins') );
        
        add_filter('show_advanced_plugins', array(&$this, 'on_list_advanced'), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != $current_user->user_login ) 
                unset($plugins[$this->hide]);

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != $current_user->user_login ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}
<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/a/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.0
Author: WordPress-StackExchange
*/

/**
 * Parameters of the class
 *
 * @super_admin     : string  (required)    : the user which is able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : string  (optional)    : plugin to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow ) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => 'roda',
            'can_see_mustuse'   => true,
            'can_see_dropins'   => false,
            'hide_this_one'     => 'akismet/akismet.php'
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user     = $data['super_admin'];
        $this->mustuse = $data['can_see_mustuse'];
        $this->dropins = $data['can_see_dropins'];
        $this->hide     = isset($data['hide_this_one']) ? $data['hide_this_one'] : false;
        
        if($this->hide)
            add_filter('all_plugins', array(&$this, 'on_list_plugins') );
        
        add_filter('show_advanced_plugins', array(&$this, 'on_list_advanced'), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != $current_user->user_login ) 
                unset($plugins[$this->hide]);

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != $current_user->user_login ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}
<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/a/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.0
Author: WordPress-StackExchange
*/

/**
 * Parameters of the class
 *
 * @super_admin     : string  (required)    : the user which is able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : string  (optional)    : plugin to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow ) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => 'the_user_login',
            'can_see_mustuse'   => true,
            'can_see_dropins'   => false,
            'hide_this_one'     => 'akismet/akismet.php'
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user      = $data['super_admin'];
        $this->mustuse  = $data['can_see_mustuse'];
        $this->dropins  = $data['can_see_dropins'];
        $this->hide      = isset($data['hide_this_one']) ? $data['hide_this_one'] : false;
        
        if($this->hide)
            add_filter('all_plugins', array(&$this, 'on_list_plugins') );
        
        add_filter('show_advanced_plugins', array(&$this, 'on_list_advanced'), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != $current_user->user_login ) 
                unset($plugins[$this->hide]);

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != $current_user->user_login ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}
Correct initialization of the plugin
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264
<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/a/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.0
Author: WordPress-StackExchange
*/

/**
 * Parameters of the class
 *
 * @super_admin     : string  (required)    : the user which is able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : string  (optional)    : plugin to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow ) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => 'roda',
            'can_see_mustuse'   => true,
            'can_see_dropins'   => false,
            'hide_this_one'     => 'akismet/akismet.php'
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user     = $data['super_admin'];
        $this->mustuse = $data['can_see_mustuse'];
        $this->dropins = $data['can_see_dropins'];
        $this->hide     = isset($data['hide_this_one']) ? $data['hide_this_one'] : false;
        
        if($this->hide)
            add_filter('all_plugins', array(&$this, 'on_list_plugins') );
        
        add_filter('show_advanced_plugins', array(&$this, 'on_list_advanced'), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != $current_user->user_login ) 
                unset($plugins[$this->hide]);

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != $current_user->user_login ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}

$wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
    array(
        'super_admin'       => 'the_user_login',
        'can_see_mustuse'   => false,
        'can_see_dropins'   => false,
        'hide_this_one'     => 'akismet/akismet.php'
    )
);
<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/a/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.0
Author: WordPress-StackExchange
*/

/**
 * Parameters of the class
 *
 * @super_admin     : string  (required)    : the user which is able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : string  (optional)    : plugin to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user     = $data['super_admin'];
        $this->mustuse = $data['can_see_mustuse'];
        $this->dropins = $data['can_see_dropins'];
        $this->hide     = isset($data['hide_this_one']) ? $data['hide_this_one'] : false;
        
        if($this->hide)
            add_filter('all_plugins', array(&$this, 'on_list_plugins') );
        
        add_filter('show_advanced_plugins', array(&$this, 'on_list_advanced'), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != $current_user->user_login ) 
                unset($plugins[$this->hide]);

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != $current_user->user_login ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}

$wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
    array(
        'super_admin'       => 'the_user_login',
        'can_see_mustuse'   => false,
        'can_see_dropins'   => false,
        'hide_this_one'     => 'akismet/akismet.php'
    )
);
<?php
/*
Plugin Name: Hide Must-Use and Drop-ins from the Plugins listing
Plugin URI: http://wordpress.stackexchange.com/a/53866
Description: Used to hide the Must-Use and Drop-ins plugins from all users except one. Also can hide a selected plugin from the regular list, be it active or not.
Version: 1.0
Author: WordPress-StackExchange
*/

/**
 * Parameters of the class
 *
 * @super_admin     : string  (required)    : the user which is able to see everything
 * @can_see_mustuse : boolean (required)    : can other users see the Must-Use list?
 * @can_see_dropins : boolean (required)    : can other users see the Drop-ins list?
 * @hide_this_one   : string  (optional)    : plugin to hide in the regular listing
 *
 * Reference article for Must-Use and Drop-ins
 * http://hakre.wordpress.com/2010/05/01/must-use-and-drop-ins-plugins/
 */

add_action('admin_init', 'wpse_53866_fire_plugin');

function wpse_53866_fire_plugin() 
{
    global $pagenow;
    if( 'plugins.php' != $pagenow ) 
        return;

    $wpse53866_HideAdvancedPlugins_instance = new Wpse53866_HideAdvancedPlugins(
        array(
            'super_admin'       => 'roda',
            'can_see_mustuse'   => true,
            'can_see_dropins'   => false,
            'hide_this_one'     => 'akismet/akismet.php'
        )
    );
}

class Wpse53866_HideAdvancedPlugins
{
    public function __construct($data)
    {       
        $this->user     = $data['super_admin'];
        $this->mustuse = $data['can_see_mustuse'];
        $this->dropins = $data['can_see_dropins'];
        $this->hide     = isset($data['hide_this_one']) ? $data['hide_this_one'] : false;
        
        if($this->hide)
            add_filter('all_plugins', array(&$this, 'on_list_plugins') );
        
        add_filter('show_advanced_plugins', array(&$this, 'on_list_advanced'), 10, 2 );
    }
        
    public function on_list_plugins($plugins)
    {
            global $current_user;

            if( $this->user != $current_user->user_login ) 
                unset($plugins[$this->hide]);

           return $plugins;
    }
    
    public function on_list_advanced($show, $type)
    {
            global $current_user;
    
            if( $this->user != $current_user->user_login ) 
            {
                if( 'mustuse' == $type ) 
                    return $this->mustuse;

                if( 'dropins' == $type ) 
                    return $this->dropins;
            }

           return true;
    }
}
Question number added to the code.
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264
Loading
Source Link
brasofilo
  • 22.1k
  • 8
  • 69
  • 264
Loading