Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hiding profile tabs (i.e. messages) based on user role


  • chrishustert
    Participant

    @chrishustert

    Hi guys!
    I am trying to hide certain profile tabs (i.e. “Messages” or “Friends”) based on specific user roles.
    I have created 2 custom user roles (examples): “Pet Owner” and “Pet Groomer”

    Both user roles are supposed to NOT be able to see/click the Tabs “Messages” and “Friends”.

    What do I have to type into the bp-custom.php? I have tried a few things but they destroyed my site… so I better don’t post my tries 😉
    And where do I find my custom user role slugs after creating them?

    Thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m note sure how your custom roles were created, so I can’t tell you how to figure out if the current user is one or the other, but basically, you’ll be using code like this:

    
    function bpcodex_remove_member_tab_on_role() {
      $role = 'owner;
      if ( 'owner' == $role ) {
    	bp_core_remove_nav_item( 'messages' );
    	bp_core_remove_nav_item( 'friends' );
      }
    }
    add_action( 'bp_actions', 'bpcodex_remove_member_tab_on_role' );
    

    note that this will not work as is–you need to be able to get the current user’s role, dependent on how you’re doing that. However, the simpler answer is that if you’re not using the friends and messages components, just turn them off in the BuddyPress settings in wp-admin.


    chrishustert
    Participant

    @chrishustert

    Thanks David, but I have found another cool solution. It’s not Pet Owner and Pet Groomer anymore though.
    Hope it helps other people, too!

    
    **
     * Remove certain tabs from user profile based on member role.
     */
    function buddydev_remove_tabs_based_on_member_roles() {
    	if ( ! bp_is_user() ) {
    		return;
    	}
        
        $premium_dog_owner = bp_current_user_can( 'premium_dog_owner' );
        $premium_dog_borrower = bp_current_user_can( 'premium_dog_borrower' );
        
        $premium_user = ($premium_dog_owner ? : $premium_dog_borrower);
        
        if ( ! $premium_user ) {
            bp_core_remove_nav_item( 'friends' ); //removes the tab friends
            bp_core_remove_nav_item( 'messages' ); //removes the tab messages
            bp_core_remove_nav_item( 'reviews' ); //removes the tab reviews
        }
    
    }
    
    add_action( 'bp_setup_nav', 'buddydev_remove_tabs_based_on_member_roles', 1001 );
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar