Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
add_action( 'gform_activate_user', 'my_gform_activate_user', 10, 3 );
function my_gform_activate_user ( $user_id, $user_data, $signup_meta ) {
$lead = RGFormsModel::get_lead( $signup_meta['lead_id'] );
if ( isset( $lead['form_id'] ) && ( $form = RGFormsModel::get_form_meta( $lead['form_id'] ) ) ) {
$on_registration = isset( $form['groups']['on_registration']['enabled'] ) ? $form['groups']['on_registration']['enabled'] : false;
$on_submission_field = isset( $form['groups']['on_submission']['field'] ) ? $form['groups']['on_submission']['field'] : null;
if ( $on_registration ) {
// by field
if ( $on_submission_field ) {
$entry = GFAPI::get_entry($signup_meta['entry_id']);
$values = $entry[$on_submission_field];
$values = explode(',', $values);
if ( is_array( $values ) ) {
foreach( $values as $key => $value ) {
if ( $group = Groups_Group::read_by_name( $value ) ) {
Groups_User_Group::create( array( 'user_id' => $user_id, 'group_id' => $group->group_id ) );
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.