Skip to content

Commit 032b949

Browse files
authored
Merge pull request #54 from mailchimp/fix/53
Fix the PHP warning and hide the form until a list is selected in the settings.
2 parents cd3a3fc + f57f059 commit 032b949

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/mailchimp/mailchimp.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ public function post( $endpoint, $body, $method = 'POST' ) {
188188
foreach ( $merges as $merge ) {
189189
if ( empty( $body['errors'] ) ) {
190190
// Email address doesn't come back from the API, so if something's wrong, it's that.
191-
$field_name = 'Email Address';
192-
$body['errors'][0]['message'] = 'Please fill out a valid email address.';
193-
} elseif ( $merge['tag'] === $body['errors'][0]['field'] ) {
191+
$field_name = esc_html__( 'Email Address', 'mailchimp' );
192+
$body['errors'][0]['message'] = esc_html__( 'Please fill out a valid email address.', 'mailchimp' );
193+
} elseif ( ! empty( $body['errors'] ) && isset( $body['errors'][0]['field'] ) && $merge['tag'] === $body['errors'][0]['field'] ) {
194194
$field_name = $merge['name'];
195195
}
196196
}

mailchimp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function mailchimp_sf_request_handler() {
217217
}
218218

219219
// erase auth information
220-
$options = array( 'mc_api_key', 'mailchimp_sf_access_token', 'mc_datacenter', 'mailchimp_sf_auth_error', 'mailchimp_sf_waiting_for_login', 'mc_sopresto_user', 'mc_sopresto_public_key', 'mc_sopresto_secret_key' );
220+
$options = array( 'mc_api_key', 'mailchimp_sf_access_token', 'mc_datacenter', 'mailchimp_sf_auth_error', 'mailchimp_sf_waiting_for_login', 'mc_sopresto_user', 'mc_sopresto_public_key', 'mc_sopresto_secret_key', 'mc_list_id' );
221221
mailchimp_sf_delete_options( $options );
222222
break;
223223
case 'change_form_settings':
@@ -1403,5 +1403,5 @@ function mailchimp_sf_get_access_token() {
14031403
* @return bool
14041404
*/
14051405
function mailchimp_sf_should_display_form() {
1406-
return mailchimp_sf_get_api() && ! get_option( 'mailchimp_sf_auth_error' );
1406+
return mailchimp_sf_get_api() && ! get_option( 'mailchimp_sf_auth_error' ) && get_option( 'mc_list_id' );
14071407
}

views/setup_page.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// If we have an API Key, see if we need to change the lists and its options
1212
mailchimp_sf_change_list_if_necessary();
13+
14+
$is_list_selected = false;
1315
?>
1416
<div class="wrap">
1517
<hr class="wp-header-end" />
@@ -76,7 +78,15 @@
7678
</div>
7779
<?php
7880
} else {
79-
$lists = $lists['lists'];
81+
$lists = $lists['lists'];
82+
$option = get_option( 'mc_list_id' );
83+
$list_ids = array_map(
84+
function ( $ele ) {
85+
return $ele['id'];
86+
},
87+
$lists
88+
);
89+
$is_list_selected = in_array( $option, $list_ids, true );
8090
?>
8191
<table class="mc-list-select" cellspacing="0">
8292
<tr class="mc-list-row">
@@ -86,7 +96,6 @@
8696
<option value=""> &mdash; <?php esc_html_e( 'Select A List', 'mailchimp' ); ?> &mdash; </option>
8797
<?php
8898
foreach ( $lists as $list ) {
89-
$option = get_option( 'mc_list_id' );
9099
?>
91100
<option value="<?php echo esc_attr( $list['id'] ); ?>"<?php selected( $list['id'], $option ); ?>><?php echo esc_html( $list['name'] ); ?></option>
92101
<?php
@@ -110,7 +119,7 @@
110119

111120
<?php
112121
// Just get out if nothing else matters...
113-
if ( get_option( 'mc_list_id' ) === '' ) {
122+
if ( ! $is_list_selected ) {
114123
return;
115124
}
116125

0 commit comments

Comments
 (0)