The gform_user_registered action is used to trigger an event once a user has been registered through the User Registration Add-on.
Usage
add_action('gform_user_registered', 'your_function_name', 10, 4);
Parameters
- $user_id (integer): The ID of the registered user.
- $feed (Feed Object): The Feed which is currently being processed.
- $entry (Entry Object): The entry object from which the user was registration.
- $user_pass (string): The password associated with the user; either submitted by the user or sent via email from WordPress.
More information
See Gravity Forms Docs: gform_user_registered
Examples
Update user meta
In this example, a custom user meta value is added for the newly registered user:
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
Set the user role based on the value of a field (field ID 5 in this example):
add_action('gform_user_registered', 'set_user_role', 10, 3);
function set_user_role($user_id, $feed, $entry) {
$selected_role = rgar($entry, '5');
$user = new WP_User($user_id);
$user->set_role($selected_role);
}
Trigger Mailchimp feed
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
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
Add an additional user role based on the value of a field (field ID 6 in this example):
add_action('gform_user_registered', 'add_user_role', 10, 3);
function add_user_role($user_id, $feed, $entry) {
$additional_role = rgar($entry, '6');
$user = new WP_User($user_id);
$user->add_role($additional_role);
}