How to hide certain plugins from administrators

I need to have certain "tech" plugins run on customer's site without them having an easy way of disabling them. This is not to hide "bad" plugins from them, simply some must-have plugins that they should not touch (some clients I need to give admin accounts)

So far, I thought about trying to see if the plugins I need to hide can run from the mu-plugins folder, that would hide them from the plugins page in the backend but would possibly still show their menus.

Then I found this solution in the wordpress forums: http://wordpress.org/support/topic/how-to-a-hide-plugin-from-username?replies=12

To be used within functions.php

function mytest() {
  global $wp_list_table;
  $hidearr = array('plugin-folder/plugin.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', 'mytest' )

But I'm not 100% sure if one of these or another method is recommended?

  • jeff_beyer
    • Design Lord, Child of Thor

    Just a thought, have you considered using Roles and creating a custom roles for your users that have the same set of permissions that an admin does with the exception of seeing the plugin menus? You could call it something like "Site Manager".

  • Ovidiu
    • Code Wrangler

    I have briefly experimented with that but I would need a plugin i.e. user role editor to create and edit roles and do this manually for all sites of my customers so I thought a general way to hide specific plugins would be easier to duplicate across multipel sites...

  • aecnu
    • WP Unicorn

    Greetings Ovidiu,

    Thank you for letting us know about the coding and your trying out the other plugins i.e. user role editor etc. in the past and why you do not want to use these plugins now - and it makes perfect sense.

    However, what are you looking for here with this ticket? Approval of the coding snippet in your initial post or?

    Does that snippet indeed work?

    Please advise.

    Cheers, Joe

  • Ovidiu
    • Code Wrangler

    hey Joe,

    I just posted here to see if anyone more advanced has a better/easier idea or if someone knows of another solution :slight_smile:
    hence my post here in the advanced section...

    just checking :slight_smile:

    as to the snippet I haven't tested it yet but it looks like it would indeed hide a plugin from the list so the question related to the snippet would be if it is somehow possible to not only hide a plugin from the list but also its menu?

  • jeff_beyer
    • Design Lord, Child of Thor

    I would try it out. If you can accomplish this in the functions.php file without the need of a plugin (and the overhead that comes with it) that would be even better. From what I read about the wp_list_table you are definitely on the right track, I believe this can be used to modify all admin menu's.

  • Ovidiu
    • Code Wrangler

    I tried this (just an example) and it does indeed hide the plugin from the plugins list but not its menu :slight_frown:
    Any other idea how to also hide all menus created by a certain plugin automatically?

    If not, this is already a step in the right direction :slight_smile:

    //test hiding plugins
    function mytest() {
      global $wp_list_table;
      $hidearr = array('all-in-one-seo-pack/all_in_one_seo_pack.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', 'mytest' );
  • aecnu
    • WP Unicorn

    Greetings Ovidiu,

    Thank you for the additional input and the coding you submitted.

    I am curious as to why you just do not remove the plugins menu selection completely?

    To be on the current path, are you referring to hiding certain plugins from the list of available plugins which is what I understand?

    Please advise.

    Cheers, Joe

  • Ovidiu
    • Code Wrangler

    I offer managed hosting and some customers insist on getting an ADMIN account and I can't completely hide the plugin menu, I just need to hide certain plugins and their menus, i.e. the nginx-helper plugin is needed since I host using nginx to give you an example.

    or, some other clients are on a simple hosting plan, not wanting to pay for any maintenance to their sites so I NEED them to have the wordfence plugin running, this way, even if their installation gets compromised I get a notification via the periodic scan so I don't want them to see or disable the wordfence plugin.

    Does that make sense to you?

  • Noahj Champion
    • Site Builder, Child of Zeus

    Question:
    How does hiding a plugin this way from the plugin section affect plugin updates? Would the update message/notification show? If the update shows can it still be updated through Wordpress's mass update of selected plugins through it's dashboard?

    Thanks, if any can answer properly.

  • Noahj Champion
    • Site Builder, Child of Zeus

    Hey @PC, thanks.

    That's good to know. I haven't got into Wordpress Multisite yet. I did achieve this fro single installs by adding some css to not display the update notification icons in the admin menu bar. Apart from there, I used Admin Menu Editor from Wordpress.org to disable the "Updates" menu option for other users. My clients have a "Client" role, so as Administrator they won't see any notifications. The only notifications that show now are in the actual plugins menu. For most clients, I don't think they will be drawn to that part without a real reason to go there or draw their attention to there. And even there I hid some plugins from that list, so all is well.

    Thanks for the heads on on multisite installs.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.