0

my code below works like a charm for logged in users to hide certain tabs:

function bpfr_hide_activity_nav() {
    if( !current_user_can( 'subscriber' ) ){
        return;
    } 
    bp_core_remove_nav_item( 'media' );
    bp_core_remove_nav_item( 'forums' );
    bp_core_remove_nav_item( 'orders' );
    bp_core_remove_nav_item( 'activity' );
}
add_action( 'bp_ready', 'bpfr_hide_activity_nav' );

But for visitors/logged out users, the tabs are still visible in the members profile where role is set to Subscriber. My code is based in current_user_can, how can I transform this into profile-I-see-on-page-has-to-be-effected option?

Hope someone can point me in the right direction. Thanks.

1 Answer 1

1
+50

I think the function you are looking for is bp_displayed_user_id(). That will get the ID of the user whose profile is currently being displayed.

Then, you can check their role like this:

$user = get_userdata( bp_displayed_user_id() );
if ( ! in_array( 'subscriber', (array) $user->roles ) ) {
    return;
} 

You could also use user_can(), but it is best to avoid using role names with user_can() and current_user_can(), as they are really designed for capabilities and not roles. In fact, you ideally would not check user roles in a case like this at all. It would be better to add a custom capability to certain roles, like 'extended_bp_profile', and then check for that instead.

1
  • works like a charm @j-d, thank you very much and bounty well spend :)
    – AKNL
    Nov 5, 2017 at 9:19

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.