bookmark_bordergform_user_updated

Description

This action is used to trigger an event once a user has been updated through the User Registration Add-on.

Usage

The following would apply to all forms with an update feed.

add_action( 'gform_user_updated', 'your_function_name', 10, 4 );

Parameters

  • $user_id integer

    The ID of the logged in user.

  • $feed Feed Object

    The Feed which is currently being processed.

  • $entry Entry Object

    The entry object from which the user was updated.

  • $user_pass string

    The password associated with the user; either submitted by the user or automatically generated.

Examples

1. Update User Role

Below is an example that updates the user role based on data submitted on the form.

add_action( 'gform_user_updated', 'change_role', 10, 4 );
function change_role( $user_id, $feed, $entry, $user_pass ) {
    //set the role based on data submitted, test form has 3 drop downs with the text true and false as the options
    //change this based on your fields/data
    $question1 = rgar( $entry, '4' ); //field id 4
    $question2 = rgar( $entry, '5' ); //field id 5
    $question3 = rgar( $entry, '6' ); //field id 6

    if ( $question1 == 'true' && $question2 == 'true' && $question3 'true' ) {
        //update role
        $user_obj = new WP_User( $user_id );
        $user_obj->set_role( 'administrator' );
    }
}

2. Update Display Name

The following example shows how you can update the display name using a field value

add_action( 'gform_user_updated', 'update_display_name', 10, 4 );
function update_display_name( $user_id, $feed, $entry, $user_pass ) {
    // get display name from field 2
    $display_name = rgar( $entry, '2' );
    if ( ! empty( $display_name ) ) {
        update_user_meta( $user_id, 'display_name', $display_name );
    }
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

do_action( 'gform_user_updated', $user_id, $feed, $entry, $user_data['password'] );

This filter is located in GF_User_Registration::update_user() in class-gf-user-registration.php