Skip to:
Content
Pages
Categories
Search
Top
Bottom

BuddyPress – Auto join group


  • remocode
    Participant

    @remocode

    I wanna automatically add new registered user to corresponding group by Buddypress.
    Here is my code put in the theme’s functions.

    function automatic_group_membership( $user_id ) {
    
           if( !$user_id ) return false;
    
            $join_group = xprofile_get_field_data(2, $user_id);  // 2 is xprofile field_id
    
            // conditionnal
            if ($join_group == "Group1") // Group Name
                $group_id = 3; // Group id
    
            // action
            groups_accept_invite( $user_id, $group_id );
    
        }
    
        add_action( 'bp_core_activated_user', 'automatic_group_membership' );

    But it doesn’t work.

    How can I figure out this problem?

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