Skip to content

Commit 3199b7a

Browse files
committed
Display an error message informing the user to subscribe through the hosted form if they were previously unsubscribed.
1 parent ece5aa3 commit 3199b7a

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

lib/mailchimp/mailchimp.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,28 @@ public function post( $endpoint, $body, $method = 'POST', $list_id = '' ) {
190190
$merges = get_option( 'mailchimp_sf_merge_fields_' . $list_id );
191191
}
192192

193+
// Check if the email address is in compliance state.
194+
if ( ! isset( $body['errors'] ) && isset( $body['status'] ) && isset( $body['title'] ) && 400 === $body['status'] && 'Member In Compliance State' === $body['title'] ) {
195+
$url = mailchimp_sf_signup_form_url( $list_id );
196+
$message = wp_kses(
197+
sprintf(
198+
/* translators: %s: Hosted form Url */
199+
__(
200+
'The email address cannot be subscribed because it was previously unsubscribed, bounced, or is under review. Please <a href="%s" target="_blank">sign up here.</a>',
201+
'mailchimp'
202+
),
203+
esc_url( $url )
204+
),
205+
[
206+
'a' => [
207+
'href' => [],
208+
'target' => [],
209+
],
210+
]
211+
);
212+
return new WP_Error( 'mc-subscribe-error-compliance', $message );
213+
}
214+
193215
$field_name = '';
194216
foreach ( $merges as $merge ) {
195217
if ( empty( $body['errors'] ) ) {

mailchimp.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,13 +1224,16 @@ function mailchimp_sf_update_profile_url( $email ) {
12241224
/**
12251225
* Get signup form URL.
12261226
*
1227+
* @param string $list_id List ID
12271228
* @return string
12281229
*/
1229-
function mailchimp_sf_signup_form_url() {
1230-
$dc = get_option( 'mc_datacenter' );
1231-
$user = get_option( 'mc_user' );
1232-
$list_id = get_option( 'mc_list_id' );
1233-
$url = 'http://' . $dc . '.list-manage.com/subscribe?u=' . $user['account_id'] . '&id=' . $list_id;
1230+
function mailchimp_sf_signup_form_url( $list_id = '' ) {
1231+
$dc = get_option( 'mc_datacenter' );
1232+
$user = get_option( 'mc_user' );
1233+
if ( empty( $list_id ) ) {
1234+
$list_id = get_option( 'mc_list_id' );
1235+
}
1236+
$url = 'http://' . $dc . '.list-manage.com/subscribe?u=' . $user['account_id'] . '&id=' . $list_id;
12341237
return $url;
12351238
}
12361239

views/css/frontend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
?>
9-
.mc_error_msg {
9+
.mc_error_msg, .mc_error_msg a {
1010
color: red;
1111
margin-bottom: 1.0em;
1212
}

0 commit comments

Comments
 (0)