BuddyDev

Search

[Resolved] Disable BuddyPress 'Join Group' and 'Add friend' based on user's role


  • Participant
    Level: Initiated
    Posts: 2
    Emmanuel on #2768

    Hi,

    I’d like to disable the Join Group Button and Add Friend Button for certain users with a particular role. So far I’ve been able to filter non members from the BuddyPress members. But I’d like to restrict users with certain roles from using certain features like joining groups and adding friends.

    Regards,
    Emmanuel


  • Keymaster
    (BuddyDev Team)
    Posts: 15855
    Brajesh Singh on #2773

    Hi Emmanuel,
    Welcome to BuddyDev forums.

    It is doable and there can be multiple ways to do it. Are you comfortable with php code? If yes, I can guide in the right direction.

    Thank you
    Brajesh


  • Participant
    Level: Initiated
    Posts: 2
    Emmanuel on #2774

    Hi Brajesh,

    Yes i’m quite comfortable with php code. Guidance would be great.

    Regards,
    Emmanuel


  • Keymaster
    (BuddyDev Team)
    Posts: 15855
    Brajesh Singh on #2775

    Hi Emmanuel,
    Here are some example code to show hiding the buttons for specific oles

    
    
    add_filter( 'bp_get_group_join_button', 'custom_hide_joingroup_button');
    function custom_hide_joingroup_button( $btn) {
    
    	if ( ! current_user_can('manage_options' ) ) {
    		unset( $btn['id'] );//unsetting id will fore BP_Button to not generate any content
    	}
    
    	return $btn;
    }
    
    add_filter( 'bp_get_add_friend_button', 'custom_hide_addfriend_button' );
    function custom_hide_addfriend_button( $btn ) {
    	if ( ! current_user_can('manage_options' ) ) {
    		unset( $btn['id'] );//unsetting id will fore BP_Button to not generate any content
    	}
    
    	return $btn;
    }
    

    Please take a look at this table to see which capability you may use.

    Hope that it helps.


  • Keymaster
    (BuddyDev Team)
    Posts: 15855
    Brajesh Singh on #2776

  • Participant
    Level: Initiated
    Posts: 2
    Emmanuel on #2777

    Awesome, worked flawlessly. Never realised the power of ‘current_user_can’. I should be able to hide other BuddyPress buttons with this method.

    Thanks again Brajesh!


  • Keymaster
    (BuddyDev Team)
    Posts: 15855
    Brajesh Singh on #2778

    No problem.
    You are most welcome.
    Happy coding 🙂

The topic ‘ [Resolved] Disable BuddyPress 'Join Group' and 'Add friend' based on user's role’ is closed to new replies.

This topic is: resolved
Subscribe