'Make a buddypress profile menu page private

i am using a custom Buddypress profile menu page *(www.mydomain.com/members/username/mycomponentpage )*that is public.

I would like to make this profile menu page private for each user and also remove it for the role of subscriber.

Basically i would like this page to have the same behavior like www.mydomain.com/members/username/settings page.

I started something like that

function hide_mycomponentpage (){

global $bp;

if (!is_user_logged_in() && bp_is_current_component( 'mycomponentpage' ) ) {
        bp_core_no_access();
    }elseif ( bp_current_user_can('subscriber') ){
        bp_core_remove_nav_item('mycomponentpage');
    }else {//make the page private, same behaviour as /members/username/settings , maybe with bp_core_catch_no_access()  }
}
add_action( 'bp_init', 'hide_mycomponentpage ');

But the code is not correct. I would appreciate any help please



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source