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

  • $override boolean

    The default is true.

  • $form Form Object

    The form which is currently being processed.

  • $entry Entry Object

    The entry which is currently being processed.

  • $feed Feed Object

    The feed which is currently being processed.

Examples

1. Override all feeds

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

add_filter( 'gform_mailchimp_override_empty_fields', '__return_false' );

2. Override specific 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

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

Source Code

apply_filters( "gform_mailchimp_override_empty_fields_{$form['id']}", apply_filters( 'gform_mailchimp_override_empty_fields', true, $form, $entry, $feed ), $form, $entry, $feed )

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