Skip to:
Content
Pages
Categories
Search
Top
Bottom

allow members to join only 1 group


  • psmorrow
    Participant

    @psmorrow

    Hi there,
    I’d like to limit the number of groups that a member can join to only 1. Can anyone provide some guidance on counting the number of groups a member has joined and if greater than zero, hide the “join group” button?
    Many thanks in advance!

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

  • psmorrow
    Participant

    @psmorrow

    Hello Kind souls.
    A please for assistance on the post above.
    Sincerely,
    Pete


    psmorrow
    Participant

    @psmorrow

    function bp_remove_group_join_button2( $button, $group ) {
    
    	$user_id = bp_loggedin_user_id();
    	$result = groups_total_groups_for_user($user_id);
    
    	if ( $result > 0 ) {
    
    		return '';
    	}
    
    	return $button;
    	
    }	
    add_filter( 'bp_get_group_join_button', 'bp_remove_group_join_button2', 10, 2);
    

    psmorrow
    Participant

    @psmorrow

    This solution is even better because it displays the leave group button, which could be helpful, if you want to restrict users to 1 group only, but be able to leave 1 group and join another….

    function action_groups_member_before_save( $array ) { 
    	
    	$user_id = bp_loggedin_user_id();
    	$result = groups_total_groups_for_user($user_id);
    
    	if ( $result > 0 ) {
    
    		wp_die('You can only join 1 group	');
    	}
    
    	return $button;
    
    	}
    
    add_action( 'groups_member_before_save', 'action_groups_member_before_save', 10, 1 ); 
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar