The gform_mailchimp_override_empty_fields filter allows you to prevent empty form fields from erasing values already stored in the mapped Mailchimp MMERGE fields when updating an existing subscriber.
Usage
A generic example of the filter, which runs for all Mailchimp feeds:
add_filter('gform_mailchimp_override_empty_fields', 'your_function_name', 10, 4);
To target a specific form, append the form ID to the hook name (format: gform_mailchimp_override_empty_fields_FORMID):
add_filter('gform_mailchimp_override_empty_fields_10', 'your_function_name', 10, 4);
Parameters
- $override (boolean): The default is true.
- $form (Form Object): The form currently being processed.
- $entry (Entry Object): The entry currently being processed.
- $feed (Feed Object): The feed currently being processed.
More information
See Gravity Forms Docs: gform_mailchimp_override_empty_fields
Examples
Override all feeds
This example shows how to apply the filter to all Mailchimp feeds:
add_filter('gform_mailchimp_override_empty_fields', '__return_false');
Override specific feed
This example shows how to target a specific Mailchimp feed:
add_filter('gform_mailchimp_override_empty_fields', function($override, $form, $entry, $feed) { $feed_name = rgars($feed, 'meta/feedName'); return $feed_name == 'Your feed name' ? false : $override; }, 10, 4);
Override feed for a specific form
This example shows how to target a specific Mailchimp feed for a specific form:
add_filter('gform_mailchimp_override_empty_fields_5', function($override, $form, $entry, $feed) { $feed_name = rgars($feed, 'meta/feedName'); return $feed_name == 'Your feed name' ? false : $override; }, 10, 4);
Override based on form field value
This example shows how to override the empty fields behavior based on a form field value:
add_filter('gform_mailchimp_override_empty_fields', function($override, $form, $entry, $feed) { $field_value = rgar($entry, '1'); // Replace '1' with the field ID return $field_value == 'Your desired value' ? false : $override; }, 10, 4);
Override based on a custom condition
This example shows how to override the empty fields behavior based on a custom condition:
add_filter('gform_mailchimp_override_empty_fields', function($override, $form, $entry, $feed) { // Add your custom condition here $custom_condition = true; return $custom_condition ? false : $override; }, 10, 4);
Place your code snippet in the functions.php
file of your active theme.