groups_join_group not working in 10.2.0, worked in 9.0
-
I’m trying to get groups_join_group to work when submitting a gravity form to create a user. All other fields are attached but they are not joining the group. This worked in 9.0
Issue:
// Create a new user $new_user_id = wp_insert_user( $userdata ); // GFCommon::log_debug( __METHOD__ . '(): form => ' . print_r( $birthdate, true ) ); if ( ! is_wp_error( $new_user_id ) ) { groups_join_group( $group_id, $new_user_id );
Full code:
add_action( 'gform_after_submission', 'add_member_gform_handle', 10, 2 ); function add_member_gform_handle( $entry, $form ) { if ( $form['title'] === 'Add Member' ) { $fields = $form['fields']; $first_name = rgar( $entry, '1' ); $last_name = rgar( $entry, '2' ); $login = rgar( $entry, '3' ); $password = rgar( $entry, '4' ); $email = rgar( $entry, '5' ); $group_id = rgar( $entry, '6' ); $role = rgar( $entry, '11' ); $notification = rgar( $entry, '9.1' ); $birthdate = rgar( $entry, '10' ); $userdata = array( 'user_login' => $login, 'user_pass' => $password, ); if ( ! empty( $first_name ) ) { $userdata['first_name'] = $first_name; } if ( ! empty( $last_name ) ) { $userdata['last_name'] = $last_name; } if ( ! empty( $email ) ) { $userdata['user_email'] = $email; } if ( ! empty( $role ) ) { $userdata['role'] = $role; } // Create a new user $new_user_id = wp_insert_user( $userdata ); // GFCommon::log_debug( __METHOD__ . '(): form => ' . print_r( $birthdate, true ) ); if ( ! is_wp_error( $new_user_id ) ) { groups_join_group( $group_id, $new_user_id ); // Make the user displayed as a staff on a clubhouse page if ( ! empty( $notification ) ) { tml_send_new_user_notifications( $new_user_id, 'both' ); } if ( ! empty( $birthdate ) ) { $date = DateTime::createFromFormat('Y-m-d', $birthdate); $date = $date->format('Ymd'); update_field('user_birthdate', $date, 'user_' . $new_user_id); } } // Delete form entry // GFAPI::delete_entry( $entry['id'] ); } }
- You must be logged in to reply to this topic.