Using Gravity Forms ‘gform_user_registration_meta_value’ PHP filter

The gform_user_registration_meta_value filter allows you to modify a value before it is saved to the user meta in Gravity Forms.

Usage

add_filter('gform_user_registration_meta_value', 'your_function_name', 10, 6);

Parameters

  • $value (string): The value to be modified.
  • $meta_key (string): The meta key as specified in the Feed Object.
  • $meta (User Registration Feed Meta): The ID of the field input currently being processed.
  • $form (Form Object): The form currently being processed.
  • $entry (Entry Object): The entry currently being processed.
  • $is_username (bool): Indicates if the current field is mapped to the username.

More information

See Gravity Forms Docs: gform_user_registration_meta_value

This filter was added in version 3.0 and is located in GF_User_Registration::get_prepared_value() in class-gf-user-registration.php.

Examples

Modify site address meta value

Override the site address meta value:

add_filter('gform_user_registration_meta_value', function ($value, $meta_key, $meta, $form, $entry, $is_username) {
    if ($meta_key == 'siteAddress') {
        $value = 'your new value';
    }
    return $value;
}, 10, 6);

Append text to user’s bio

Add custom text to the user’s bio before saving:

add_filter('gform_user_registration_meta_value', function ($value, $meta_key, $meta, $form, $entry, $is_username) {
    if ($meta_key == 'userBio') {
        $value .= ' - Custom text appended';
    }
    return $value;
}, 10, 6);

Set custom user role

Change the user role to ‘editor’ for a specific form:

add_filter('gform_user_registration_meta_value', function ($value, $meta_key, $meta, $form, $entry, $is_username) {
    if ($form['id'] == 1 && $meta_key == 'userRole') {
        $value = 'editor';
    }
    return $value;
}, 10, 6);

Set custom meta value based on a form field

Set a custom meta value based on the value of a form field (field ID 5):

add_filter('gform_user_registration_meta_value', function ($value, $meta_key, $meta, $form, $entry, $is_username) {
    if ($meta_key == 'customMeta') {
        $value = rgar($entry, '5');
    }
    return $value;
}, 10, 6);

Conditionally set meta value

Set a custom meta value if a specific form field (field ID 10) has a certain value:

add_filter('gform_user_registration_meta_value', function ($value, $meta_key, $meta, $form, $entry, $is_username) {
    if ($meta_key == 'conditionalMeta' && rgar($entry, '10') == 'yes') {
        $value = 'custom value';
    }
    return $value;
}, 10, 6);