2

I use the following snippet to hide the plugins from my plugins list:

function hide_plugin_trickspanda() {
  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_plugin_trickspanda');

This works but when I used this on a WordPress MS, it works for all the sites, but the Network admin.

I found out that Network Admin uses active_sitewide_plugins hook for this task, but I can't find any real way to do it.

According to this site:

FYI => I was pulling an error with a plugin I developed and ended up trolling around the bowels of WordPress, specifically WordPress multisite.

WordPress single-site has a site get_option ‘active_plugins’. For WP multisite it’s get_site_option ‘active_sitewide_plugins’. The issue is, single-site uses an array with numbers—representing plugin load order—as they key. Like this:

[0] => hello-dolly/hello.php

On the other hand, WP multisite uses an associative array with the plugin name as the key and some integer as the value. Like this:

[hello-dolly/hello.php] => 1369572703

The broader issue was to manipulate the load order of the plugins. Once I understood the array types were different I added an is_mutisite() conditional and manipulated the arrays appropriately. When I find out why the array types are different I’ll let you know.

Any ideas?

1 Answer 1

4

There's a filter called all_plugins that seems to do the trick for me:

add_filter( 'all_plugins', 'wpse156903_hide_plugins' );
function wpse156903_hide_plugins( (array) $plugins ) {

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

    // hide multiple plugins
    $hidearr = array(
        'plugin1/plugin-file.php',
        'plugin2/plugin-file2.php',
        // and so on
    );
    foreach( $hidearr as $hide_me ) {
        if( in_array( $hide_me, array_keys( $plugins ) ) ) {
            unset( $plugins[$hide_me] );
        }
    }
    return $plugins;
}

Of course you'd replace akismet/akismet.php with the path to your plugin file. (I picked on Akismet because it's the first plugin in the list on my site.)

This function masks the existence of the plugin in question in both the Network > Plugins and Site > Plugins lists.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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