Description
This action is used to trigger an event once a user has been registered through the User Registration Add-on.
Usage
Applies to all forms
add_action( 'gform_user_registered', 'your_function_name', 10, 4 );
Parameters
Parameter | Type | Description |
---|---|---|
$user_id | integer | The ID of the user that was created. |
$feed | Feed Object | The feed currently being processed. |
$entry | Entry Object | The entry currently being processed. |
$user_pass | string | The value of the mapped password field from the entry or an automatically generated password. Note: The user entered password is not available when the feed is processed in the background or when the delayed feed is processed by a payment add-on. |
Examples
Update user meta
Here is an example from the User Registration source code where BuddyPress profile data is added for the user using the gform_user_registered hook.
add_action( 'gform_user_registered', 'add_custom_user_meta', 10, 4 );
function add_custom_user_meta( $user_id, $feed, $entry, $user_pass ) {
update_user_meta( $user_id, 'user_confirmation_number', rgar( $entry, '1' ) );
}
Set user role
The following example shows how you can set the user role based on the value of a field.
add_action( 'gform_user_registered', 'set_user_role', 10, 3 );
function set_user_role( $user_id, $feed, $entry ) {
// get role from field 5 of the entry.
$selected_role = rgar( $entry, '5' );
$user = new WP_User( $user_id );
$user->set_role( $selected_role );
}
Trigger Mailchimp feed
This example shows how you can trigger the processing of Mailchimp feeds for this entry.
add_action( 'gform_user_registered', 'send_to_mailchimp', 10, 3 );
function send_to_mailchimp( $user_id, $feed, $entry ) {
if ( function_exists( 'gf_mailchimp' ) ) {
$form = GFAPI::get_form( $entry['form_id'] );
gf_mailchimp()->maybe_process_feed( $entry, $form );
}
}
Update entry created_by property
This example shows how you can update the entry created_by property with the ID of the new user.
add_action( 'gform_user_registered', 'sh_gform_user_registered', 10, 3 );
function sh_gform_user_registered( $user_id, $config, $entry ) {
GFAPI::update_entry_property( $entry['id'], 'created_by', $user_id );
}
Add additional user role
This example shows how you can add an additional user role based on the value of a field.
add_action( 'gform_user_registered', 'add_user_role', 10, 3 );
function add_user_role( $user_id, $feed, $entry ) {
// get role from field 5 of the entry.
$selected_role = rgar( $entry, '5' );
$user = new WP_User( $user_id );
$user->add_role( $selected_role );
}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
do_action( 'gform_user_registered', $user_id, $feed, $entry, $user_data['password'] );
This filter is located in GF_User_Registration::create_user() in class-gf-user-registration.php.