Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Add user to group automatically

@carlen

Participant

Thank you! this did help me realize where my errors were, but wasn’t working because I am using some code of automatic login. For anyone else this is what I came up with that works.

I set up https://gravitywiz.com/documentation/gravity-forms-populate-anything/ and grab the groups from the wp database. I have them search and select the name, and then pass the value (ID) this to a hidden field.

I then set up the following code. Included is some code to automatically log them in after they register too.

function ip_gravity_registration_autologin( $user_id, $user_config, $entry, $password ) {
   $selected_team = rgar( $entry, '13' ); // Replace with the field for group ID	$group_id = $selected_team; //change it to the group ID of your choice
    groups_join_group( $group_id, $user_id );
// Automatic Login: Only automatically login if we aren't *already* logged in
if ( ! is_user_logged_in() ) { 
// Get the user data (for the login)
   $user = get_userdata( $user_id );
// Sign the user in
wp_signon( array(
'user_login' => $user->user_login,
'user_password' => $password,
'remember' => false, // Don't set the remember cookie
) );
}
}
add_action( 'gform_user_registered', 'ip_gravity_registration_autologin', 10, 4 );
Skip to toolbar