16 June, 2014 — Development, Snippets, WordPress

Hide A WordPress Plugin From Plugin List

I was recently working on a client site, which required me to create a custom plugin for his website. I wanted to hide the plugin from the user, as he was a beginner and the plugin contained some sensitive functions to run his website.

In this snippet, I’ll show you how you can easily hide a WordPress plugin from the plugin list. The plugin will still work, but just won’t appear in the plugin list.

Just add the following snippet to your current theme’s functions.php file:

function hide_my_plugin() {
    global $wp_list_table;
    $hidearr = array('plugin-directory/plugin-file.php');
    $myplugins = $wp_list_table->items;
    foreach ($myplugins as $key => $val) {
        if (in_array($key,$hidearr)) {
            unset($wp_list_table->items[$key]);
        }
    }
}
add_action('pre_current_active_plugins', 'hide_my_plugin');

Replace plugin-directory/plugin-file.php in above code with your plugin’s directory and file name. You can find this info by clicking on edit plugin link from the plugin list.

What about Multisite?

If you wanna hide the plugin from your WordPress Multisite, then you above snippet will not remove the plugin from the Network admin list. Here’s a snippet which will work on the WordPress Multisite

function mu_hide_plugins_network( $plugins ) {
    // let's hide akismet
    if( in_array( 'akismet/akismet.php', array_keys( $plugins ) ) ) {
        unset( $plugins['akismet/akismet.php'] );
    }
    return $plugins;
}
 
add_filter( 'all_plugins', 'mu_hide_plugins_network' );