DescriptionUsageParametersExamples1. Format Birthday2. Format SignaturePlacementSinceSource Code
Description
Use this filter to modify a value before it is sent to the Mailchimp API.
Usage
The base filter which would run for all forms and all fields would be used like so:
add_filter( 'gform_mailchimp_field_value', 'your_function_name', 10, 5 );
To target a specific form append the form id to the hook name. (format: gform_mailchimp_field_value_FORMID)
add_filter( 'gform_mailchimp_field_value_10', 'your_function_name', 10, 4 );
To target a specific field append both the form id and the field id to the hook name. (format: gform_mailchimp_field_value_FORMID_FIELDID)
add_filter( 'gform_mailchimp_field_value_10_3', 'your_function_name', 10, 4 );
Parameters
$value string
The value to be modified.
$form_id integer
The ID of the form being processed.
$field_id string
The ID of the field being processed.
$entry Entry Object
The entry currently being processed.
$merge_var_name string
The name of the mapped Mailchimp MMERGE field.
Examples
1. Format Birthday
This example takes the birthday and reformats it into mm/dd before sending. This time we』re using the form id and field id in the filter name to target only field id 3 in form id 10.
add_filter( 'gform_mailchimp_field_value_10_3', 'change_birthday', 10, 4 );
function change_birthday( $value, $form_id, $field_id, $entry ) {
// Skip processing if $value is empty.
if ( empty( $value ) ) {
return $value;
}
$month = date( 'm', strtotime( $value ) ); //get month
$day = date( 'd', strtotime( $value ) ); //get day
$date = $month . '/' . $day; //build date into format needed by Mailchimp
return $date;
}
2. Format Signature
add_filter( 'gform_mailchimp_field_value', function ( $value, $form_id, $field_id, $entry, $merge_var_name ) {
return $merge_var_name == 'SIGNATURE' ? RGFormsModel::get_upload_url_root() . 'signatures/' . $value : $value;
}, 10, 5 );
Placement
This code should be placed in the functions.php file of your active theme.
Since
The base filter was added in version 2.0. The form and field specific versions were added in version 3.7.
Source Code
gf_apply_filters( 'gform_mailchimp_field_value', array( $form['id'], $field_id ), $field_value, $form['id'], $field_id, $entry, $this->merge_var_name )
This filter is located in GFMailChimp::maybe_override_field_value() in class-gf-mailchimp.php.