gform_user_registered

gform_user_registered

DescriptionUsageParametersExamplesUpdate user metaSet user roleTrigger Mailchimp feedUpdate entry created_by propertyAdd additional user rolePlacementSource Code

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

$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.

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.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注