|

How to hide plugins from the Admin plugin list?

How to hide plugins from the Admin plugin list?

Recently i had this requirement of hide plugins from the admin plugin list. I went and did some research and after having a deep look, i was able to get two clues:

1. Either i use CSS to hide them some how, OR
2. Use some custom script in functions.php to hide.

For first one, you can try looking up for css class and add the style via your function.php. So i went into the plugin list and looked up for the classes in the html. Unfortunately, wordpress doesn’t add any specific class for the plugin.

Now the only option left was to go and look for the custom script. Luckily, i came across this hook:

do_action( ‘pre_current_active_plugins’, array $plugins_all )

This hook fires before the plugins list table is rendered, hence it is where we have way out. Below is the snippet of code that can help you identify the plugin based on its url and then remove it from the plugin list. Though the plugin will remain still active.

Suppost we want to hide the Advance Custom Fields plugin. If you look it the structure of the ACF, you will notice the main folder and main file is under the following structure: “advanced-custom-fields/acf.php”

<?php

function plugin_hide() {
global $wp_list_table;
$hidearr = array('advanced-custom-fields/acf.php'); // replace your plugin url here
$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', 'plugin_hide');

?>

If this snippet of code helped you, give us a thumbs up by following us at: Twitter and Facebook.

Reference:
https://developer.wordpress.org/reference/hooks/pre_current_active_plugins/