Using Gravity Forms ‘gform_user_updated’ PHP action

The gform_user_updated action triggers an event when a user has been updated through the User Registration Add-On.

Usage

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 sent via email from WordPress.

More information

See Gravity Forms Docs: gform_user_updated

Examples

Update User Role

This example 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
    $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');
    }
}

Update Display Name

This example updates 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);
    }
}

Add Additional Role

This example adds an additional role to user’s existing roles.

add_action('gform_user_updated', 'add_additional_role', 10, 4);
function add_additional_role($user_id, $feed, $entry, $user_pass) {
    // Run only for form id
    if (rgar($entry, 'form_id') != 1) {
        return;
    }

    GFCommon::log_debug(__METHOD__ . '(): running for User ID: ' . $user_id);
    // Role name ID to add
    $role_to_add = 'custom_role';

    // Get current user object
    $user_obj = new WP_User($user_id);
    // Add the role above to existing roles for the user
    $user_obj->add_role($role_to_add);

    GFCommon::log_debug(__METHOD__ . '(): Roles for user ' . $user_id . ': ' . print_r($user_obj->roles, true));
}