bookmark_bordergform_user_registered

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 automatically generated.

Examples

1. 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' ) );
}

2. 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 );
}

3. 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 );
    }
}

4. 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 );
}

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