Skip to content

Commit 0f87558

Browse files
committed
bugfix-remove-tags-new-subscriber
When submitting a new email I would get an error - tags[n] : This value should be of type string.
1 parent 9b6bda4 commit 0f87558

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

includes/class-mailchimp.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,24 @@ public function list_subscribe($list_id, $email_address, array $args = [], $upda
8686
}
8787

8888
try {
89+
// Extract tags from args before subscriber creation/update
90+
$tags = [];
91+
if (isset($args['tags']) && is_array($args['tags'])) {
92+
$tags = $args['tags'];
93+
unset($args['tags']);
94+
}
95+
8996
if ($existing_member_data) {
9097
$data = $api->update_list_member($list_id, $email_address, $args);
9198
$data->was_already_on_list = $existing_member_data->status === 'subscribed';
92-
93-
if (isset($args['tags']) && is_array($args['tags'])) {
94-
$this->list_tags_to_subscriber($list_id, $data, $args['tags']);
95-
}
9699
} else {
97100
$data = $api->add_new_list_member($list_id, $args);
98101
$data->was_already_on_list = false;
99102
}
103+
104+
if (!empty($tags)) {
105+
$this->list_tags_to_subscriber($list_id, $data, $tags);
106+
}
100107
} catch (MC4WP_API_Exception $e) {
101108
$this->error_code = $e->getCode();
102109
$this->error_message = $e;

0 commit comments

Comments
 (0)