mailchimp-for-wordpress icon indicating copy to clipboard operation
mailchimp-for-wordpress copied to clipboard

Abbility to remove tags

Open arnelap opened this issue 1 month ago • 1 comments

Functional changes: Changed the name of private function list_add_tags_to_subscriber to list_tags_to_subscriber Changed private function merge_and_format_member_tags to accept a tag array with status active or inactive. (add/remove) Removed array_unique(array_merge($mailchimp_tags, $new_tags), SORT_REGULAR); from merge_and_format_member_tags

Visual changes: Added a "remove_subscriber_tags" option to Form > Settings that takes a comma separated list of tags to remove Renamed the settings fields to "Add tags" and "Remove tags (was Add subscriber tags)

Unit tests:

  • Added the same unit test that existed for Add tags also to Remove tags

Testing:

  • I tested form submissions adding and removing 1 and multiple tags via the form setting(s).
  • Tested just adding, tested just removing, tested adding and removing at the same time with 1 tag each, added with multiple tags added and removed... (we could do the reverse?)
  • I tested form submissionadding and removing the same tag at the same time, removing is done later so it results in removing the tag

All the form submissions had the expected result of added tags being added, removed tags being removed and unmentioned tags remaining active.

  • I tested mc4wp_subscriber_data
//new format
add_filter('mc4wp_subscriber_data', function (MC4WP_MailChimp_Subscriber $subscriber) {
    $subscriber->tags[] = ['name' => 'remove this tag', 'status' => 'inactive'];
    $subscriber->tags[] = ['name' => 'another-removal', 'status' => 'inactive'];
    $subscriber->tags[] = ['name' => 'add this tag', 'status' => 'active'];
    $subscriber->tags[] = ['name' => 'also adding this tag']; //defaults to active
    return $subscriber;
});

//backwards compatible format still works too and defaults to status=active
add_filter('mc4wp_subscriber_data', function (MC4WP_MailChimp_Subscriber $subscriber) {
    $subscriber->tags[] = 'string-still-works';
    return $subscriber;
});

Tags with status inactive were removed if the subscriber had them, the tags not existing or the subscriber not having these tags assigned did not cause any error The tags with status active and the tags without status explicitly set were added Tags that are just a string instead of an array were added, for backwards compatibility.

arnelap avatar Dec 13 '25 11:12 arnelap

added form setting to remove tags, so with that it should close #621

arnelap avatar Dec 13 '25 11:12 arnelap

Still need to add new code snippet examples

arnelap avatar Dec 15 '25 15:12 arnelap