Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creates a group based on a field of Gravity Forms form.
add_action("gform_after_submission", "my_gform_after_submission", 10, 2);
function my_gform_after_submission ( $entry, $form ) {
$group_name = sanitize_text_field( trim( $entry['1'] ) ); // if the group's name is on the first field
if ( $group = Groups_Group::read_by_name( $group_name ) ) {
$group_id = $group->group_id;
} else {
$group_id = Groups_Group::create( array( 'name' => $group_name ) );
}
if ( $group_id ) {
$user_id = get_current_user_id();
Groups_User_Group::create( array ( 'user_id' => $user_id, 'group_id' => $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.