gform_user_registration_prepared_value

Description

This filter can be used to modify a field value before it is saved to the user meta. For a form using a Update User feed type, you may also want to use the gform_user_registration_user_data_pre_populate filter in combination with this one.

Usage

add_filter( 'gform_user_registration_prepared_value', 'your_function_name', 10, 5 );

Parameters

  • $value string

    The value to be modified.

  • $field Field Object

    The field currently being processed.

  • $input_id string

    The ID of the field input currently being processed.

  • $entry Entry Object

    The entry currently being processed.

  • $is_username bool

    Indicates if the current field is mapped to the username.

Examples

Country Code

The following example shows how you can replace the address field country value with the country code.

add_filter( 'gform_user_registration_prepared_value', function ( $value, $field, $input_id, $entry, $is_username ) {
$country_id = $field->id . '.6';
if ( $field->type == 'address' && $input_id == $country_id ) {
return GF_Fields::get( 'address' )->get_country_code( $value );
}
 
return $value;
}, 10, 5 );

US State Code

The following example shows how you can replace the address field US state value with the state code.

add_filter( 'gform_user_registration_prepared_value', function ( $value, $field, $input_id, $entry, $is_username ) {
$state_id = $field->id . '.4';
if ( $field->type == 'address' && $input_id == $state_id ) {
return GF_Fields::get( 'address' )->get_us_state_code( $value );
}
 
return $value;
}, 10, 5 );

Checkboxes as serialized data

The following example shows how to serialize values of a checkboxes field before saving to the user meta for a field with id 18.

add_filter( 'gform_user_registration_prepared_value', 'gf_serialize_checkboxes', 10, 5 );
function gf_serialize_checkboxes( $value, $field, $input_id, $entry, $is_username ) {
 
if ( $field->id == '18' && $field->type == 'checkbox' ) { // Update 18 to your field id number
// Get a comma separated list of checkboxes checked
$checked = $field->get_value_export( $entry );
 
// Convert to array
$value = explode( ', ', $checked );
 
// WordPress will automatically serialize this array before saving.
}
 
return $value;
}

Placement

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

Since

This filter was added in version 2.1.

Source Code

$value = apply_filters( 'gform_user_registration_prepared_value', $value, $field, $input_id, $entry, $is_username );

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