Using Gravity Forms ‘gform_user_registration_update_user_id’ PHP filter

The gform_user_registration_update_user_id Gravity Forms PHP filter allows you to override the user that is used to populate the form and updated when the form is submitted.

Usage

A generic example for all forms with an update type feed:

add_filter( 'gform_user_registration_update_user_id', 'your_function_name', 10, 4 );

To limit the scope of your function to a specific form, append the form ID to the end of the hook name (format: gform_user_registration_update_user_id_FORMID):

add_filter( 'gform_user_registration_update_user_id_6', 'your_function_name', 10, 4 );

Parameters

  • $user_id (integer): The ID of the user being used to populate the form and being updated on form submission.
  • $entry (Entry Object): The entry currently being processed or an empty array when the form is being rendered.
  • $form (Form Object): The form currently being processed.
  • $feed (Feed Object): The feed currently being processed.

More information

See Gravity Forms Docs: gform_user_registration_update_user_id

Examples

Override user ID for a specific form

In this example, the user ID for form ID 7 is overridden. A URL query string parameter is used to provide the ID, email address (user_email), slug (user_nicename), or login (user_login), of the user whose values should be populated into the mapped form fields. This value should also be populated into a form field. If you don’t want the user to see the value, use a hidden type field.

On submission, the ID of the user to be updated is determined using the value from the form field stored in the $entry. Feeds can be processed in a separate background process that does not have access to the $_POST and $_GET values from form display or submission.

add_filter( 'gform_user_registration_update_user_id_7', function( $user_id, $entry, $form, $feed ) {
    // Define the property being used to get the user. Supports 'email', 'id', 'slug', or 'login'.
    $key = 'email';

    // Define the name of the query string parameter being used to pass the value to the form on display.
    $query_arg = 'the_URL_param_here';

    // Define the ID of the form field the value was populated into.
    $field_id = '1';

    // Get the value from URL query string on form display or the entry field value during submission feed processing.
    $value = rgar( $entry, $field_id, rgget( $query_arg ) );

    // A value wasn't provided, returning the original ID instead, the ID of the currently logged in user.
    if ( empty( $value ) ) {
        return $user_id;
    }

    // Get the user using the specified key and value.
    $user = get_user_by( $key, $value );

    // If the user exists, return the ID.
    if ( $user ) {
        return $user->ID;
    }

    // The user doesn't exist, returning the original ID instead, the ID of the currently logged in user.
    return $user_id;
}, 10, 4 );

Note: Replace 'the_URL_param_here' with the actual query