gform_mailchimp_override_empty_fields

Description

This filter can be used to prevent empty form fields erasing values already stored in the mapped Mailchimp MMERGE fields when updating an existing subscriber.

Usage

The filter which would run for all Mailchimp feeds can be used like so:

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

ParameterTypeDescription
$overridebooleanThe default is true.
$formForm ObjectThe form which is currently being processed.
$entryEntry ObjectThe entry which is currently being processed.
$feedFeed ObjectThe feed which is currently being processed.

Examples

Override all Mailchimp feeds.

The following example shows how you can apply the filter to all Mailchimp feeds.

add_filter( 'gform_mailchimp_override_empty_fields', '__return_false' );

Override a specific Mailchimp feed.

The following example shows how you can 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 );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

This filter is located in GFMailChimp::process_feed() in class-gf-mailchimp.php.