BuddyDev

Search

Disable “Leave Group” for certain groups

  • Participant
    Level: Initiated
    Posts: 19
    EazyCast on #50238

    Hello again team!

    I was looking for (couldn’t find it) a way to stop members to leaving certain groups.

    Say I have an important group I want all my members to always be part of so I need to stop them from leaving that particular group. Is that possible?

    Thank you again!
    Bruno

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #50244

    Hi Bruno,
    Thank you for the question.

    BuddyPress does not provide any way to achieve it. It is possible to do that by hacking around some code.

    Which theme and template pack are you using? Please let me know and I will share the code.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 19
    EazyCast on #50253

    Hi Brajesh,

    I’m using Kleo with the Community template…

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #50262

    Hello Bruno,

    Please try the following code in your bp-custom file.

    
    add_filter( 'bp_get_group_join_button', function ( $args, $group ) {
    	// Replace with your group ids.
    	$groups_with_disable_leave_btn = array( 5, 36 );
    
    	if ( ! empty( $group->is_member ) && ! empty( $group->id ) && in_array( $group->id, $groups_with_disable_leave_btn ) ) {
    		$args = array();
    	}
    
    	return $args;
    }, 10, 2 );
    
    

    For more info: https://buddydev.com/docs/buddypress-guides/what-is-bp-custom-php/

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved