DescriptionUsageParametersExamples1. If a subscriber already exists, set them as subscribed2. Set the signup timestamp2. Set the Subscriber languageSinceSource Code
Description
The 「gform_mailchimp_subscription」 filter in Gravity Forms Mailchimp Add-On modifies the subscription object before it is executed.
Usage
1add_filter( 'gform_mailchimp_subscription', 'my_function', 10, 6 );
Parameters
$subscription array
Subscription arguments. See the Mailchimp API documentation for a full list of supported properties.
$list_id string
Mailchimp list ID.
$form array
The form object.
$entry array
The entry object.
$feed array
The feed object.
$member array
The existing member object. False if member does not currently exist in Mailchimp.
Examples
1. If a subscriber already exists, set them as subscribed
Doing this will avoid the double opt-in for existing members.
123456789add_filter( 'gform_mailchimp_subscription', 'update_existing', 10, 6 ); function update_existing( $subscription, $list_id, $form, $entry, $feed, $member ) { if ( $member ) { $subscription['status'] = 'subscribed'; } return $subscription;}
2. Set the signup timestamp
1234567add_filter( 'gform_mailchimp_subscription', function( $subscription, $list_id, $form, $entry, $feed, $member ) { if ( ! $member ) { $subscription['timestamp_signup'] = date( DATE_ATOM ); } return $subscription;}, 10, 6 );
2. Set the Subscriber language
The follow example uses the ICL_LANGUAGE_CODE constant provided by the WPML plugin to set the subscriber language.
1234567891011add_filter( 'gform_mailchimp_subscription', 'gf_set_subscriber_language' );function gf_set_subscriber_language( $subscription ) { GFCommon::log_debug( __METHOD__ . '(): running.' ); // Use the language code provided by WPML to set the subscriber language. if ( defined( 'ICL_LANGUAGE_CODE' ) ) { GFCommon::log_debug( __METHOD__ . '(): Setting value for ICL_LANGUAGE_CODE as subscriber language: ' . ICL_LANGUAGE_CODE ); $subscription['language'] = ICL_LANGUAGE_CODE; } return $subscription;}
Since
Added existing member object as $member parameter in 4.1.9.
Source Code
This filter is located in includes/addon/class-gf-mailchimp.php.