Code to hide plugins from subsite admins

I am trying to hide some plugins from subsite admins. I found this code but it is not working:
function hide_plugin_from_multisite( $plugins ) {
if( in_array('google-maps-widget/google-maps-widget.php', array_keys( $plugins ) ) ) {
unset( $plugins['google-maps-widget/google-maps-widget.php'] );
}
return $plugins;
}
add_filter( 'all_plugins', 'hide_plugin_from_multisite');

  • Alex Stine

    Hi Janet Chavez
    Hope you're well!

    I think the code looks pretty good. Could you please try adding it in a mu-plugin instead? To create a mu-plugin, please complete the following.
    1. Access your site via FTP or web based File Manager.
    2. Go to /wp-content/mu-plugins. If the "mu-plugins" directory does not exist, please create it.
    3. Now you need to create a file with a ".php" extension. Your file could be named "hide-plugins.php". The name is unimportant as long as it has the ".php" extension.
    4. Place this code inside the file.

    <?php
    function hide_plugin_from_multisite( $plugins ) {
    if( in_array('google-maps-widget/google-maps-widget.php', array_keys( $plugins ) ) ) {
    unset( $plugins['google-maps-widget/google-maps-widget.php'] );
    }
    return $plugins;
    }
    add_filter( 'all_plugins', 'hide_plugin_from_multisite');
    ?>

    Please let me know if this solves your issue.

    Cheers,
    Alex :smiley:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.