The gform_mailchimp_keep_existing_groups filter allows you to modify whether a user who is already subscribed to your Mailchimp list has their groups replaced when submitting the form a second time. By default, the original groups are kept, and any new ones are added.
Usage
add_filter('gform_mailchimp_keep_existing_groups', 'custom_function_name'); function custom_function_name($keep_existing) { // Your custom code here return $keep_existing; }
Parameters
- $keep_existing (boolean): Whether to keep existing groups when updating the user’s subscription (default is
true
).
More information
See Gravity Forms Docs: gform_mailchimp_keep_existing_groups
Examples
Replace groups on re-submission
This example sets $keep_existing
to false
, so that the groups are replaced when the user re-submits the form.
add_filter('gform_mailchimp_keep_existing_groups', 'replace_groups_on_resubmission'); function replace_groups_on_resubmission($keep_existing) { return false; }
Keep existing groups for a specific form
This example keeps existing groups when updating the user’s subscription for a specific form with an ID of 1.
add_filter('gform_mailchimp_keep_existing_groups_1', 'keep_existing_groups_for_specific_form'); function keep_existing_groups_for_specific_form($keep_existing) { return $keep_existing; }
Replace groups for a specific form
This example replaces groups when updating the user’s subscription for a specific form with an ID of 2.
add_filter('gform_mailchimp_keep_existing_groups_2', 'replace_groups_for_specific_form'); function replace_groups_for_specific_form($keep_existing) { return false; }
Keep existing groups based on a custom condition
This example keeps existing groups if the custom condition is met.
add_filter('gform_mailchimp_keep_existing_groups', 'keep_existing_groups_based_on_condition'); function keep_existing_groups_based_on_condition($keep_existing) { // Your custom condition here if (/* Your custom condition */) { return $keep_existing; } else { return false; } }
Replace groups based on a custom condition
This example replaces groups if the custom condition is met.
add_filter('gform_mailchimp_keep_existing_groups', 'replace_groups_based_on_condition'); function replace_groups_based_on_condition($keep_existing) { // Your custom condition here if (/* Your custom condition */) { return false; } else { return $keep_existing; } }