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' ) ){
    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


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 ) ) {

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.