How to hide BuddyPress from some subsite admins

I have installed BuddyPress on my multisite and applied the changes to wp-config.php to make it root on a secondary site following these steps.
But to prevent other subsite admins to activate the plugin, I would like to hide the plugin from the admin and the Plugins' page for the rest of the subsite admins.

I found this thread Hide plugins from other admins, but not sure what to edit on the suggested code to adapt it to hide BuddyPress on my site for the other subsite admins. Could you hep me to achieve this?

Many thanks in advance!

  • Nithin

    Hi Roy,

    Hope you are doing good today. :slight_smile:

    I checked the Multisite, and it seems like the BuddyPress plugin is activated individually for each subsite. If you don't want the subsite admins to not have access to the "Plugins" menu in the dashboard, then you can disable the checkbox for plugins enabled for "Enable administration menus" option, under Network Settings > Settings >
    Enable administration menus
    as shown in the following screenshot:

    If the above settings don't help, then you can try the following code, which should remove the BuddyPress menus, and the plugin from getting listed in the dashboard:

    <?php
    
    add_action( 'pre_current_active_plugins', 'wpmu_hide_plugins_from_list_if_not_admin' );
    function wpmu_hide_plugins_from_list_if_not_admin() {
    	if ( is_user_logged_in() ) {
    		$user = wp_get_current_user();
    		if ( '1' != $user->ID ) {
    			global $wp_list_table;
    
    			$plugins_list   = $wp_list_table->items;
    			$hidden_plugins = array( 'buddypress/bp-loader.php' );
    
    			foreach ( $plugins_list as $key => $val ) {
    				if ( in_array( $key, $hidden_plugins ) ) {
    					unset( $wp_list_table->items[ $key ] );
    				}
    			}
    		}
    	}
    }
    
    add_action( 'admin_menu', 'wpmu_hide_plugins_from_menu', 15 );
    function wpmu_hide_plugins_from_menu() {
    	if ( is_user_logged_in() ) {
    		$user = wp_get_current_user();
    		if ( '1' != $user->ID ) {
    			$menu_items = array( 'bp-activity', 'bp-groups', 'bp-components' );
    
    			foreach ( $menu_items as $menu_item ) {
    				remove_menu_page( $menu_item );
    			}
    		}
    	}
    }

    You'll have to implement the above code as a mu-plugins, please check this article for more info on how to add as mu-plugins:
    https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Since I don't see File Manager plugin enabled, I'm not sure whether you are comfortable with us adding the above code. Please do add the code as instructed in the above manual, and let us know if you have any further query.

    Have a nice day ahead. :slight_smile:

    Regards,
    Nithin

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.