Skip to:
Content
Pages
Categories
Search
Top
Bottom

hide profile subnav when displayed user does NOT have role


  • entoen
    Participant

    @kamerhuren

    hi, i am searching everywhere but i cannot find a way to hide a subnav element (‘Bookings’,’Calendar’) on a profile page when the displayed user does NOT have a certain role (Author).

Viewing 8 replies - 1 through 8 (of 8 total)

  • Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    You can check this https://buddypress.org/support/topic/hiding-profile-tabs-i-e-messages-based-on-user-role/ and use bp_core_remove_subnav_item.

    Thanks


    entoen
    Participant

    @kamerhuren

    Hi, thank you for your message. The link shows solutions for the role a visitor has when on a profile page. I would like to remove a tab on a profile when the profile owner (bp_displayed_user_id) doesn’t have a certain role.
    I think i am close but i could be miles off:(
    Here is where i am but it doesnt work

    //Disable bookings subnav by role of the displayed user id.
     
    function remove_bookingtab_by_displayed_role() {
    
        // Get Current User Data.
        $user = get_userdata( bp_displayed_user_id() );
    
        // Get Roles.
        $roles = (array) $user->roles;
    	
    // exclamationmark means not in array i hope
        if (!in_array( 'translator', $roles ) ) {
    		bp_core_remove_subnav_item( 'bookings','booking' );
    	}
    	
    }
    
    add_action( 'bp_setup_nav', 'function remove_bookingtab_by_displayed_role', 15 );
    

    Prashant Singh
    Participant

    @prashantvatsh

    add_action( 'bp_setup_nav', 'function remove_bookingtab_by_displayed_role', 15 );

    Please replace the above line with this:

    add_action( 'bp_setup_nav', 'remove_bookingtab_by_displayed_role', 15 );


    entoen
    Participant

    @kamerhuren

    hi, thanks for pointing that out. it still doesn’t work. could you point me in a direction where the problem could be?


    entoen
    Participant

    @kamerhuren

    i found out that it only work when i try to remove a core buddypress nav like ‘messages’ or ‘friends’. With a custom nav or subnav it doesn’t work. Any ideas why?


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Please try changing the priority from ’15’ to ‘9999’ and then test.

    Thanks


    entoen
    Participant

    @kamerhuren

    YES!!!
    Thank you so much for your help.


    Prashant Singh
    Participant

    @prashantvatsh

    Glad to help you 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.
Skip to toolbar