Skip to content

Commit

Permalink
Merge pull request #54 from mailchimp/fix/53
Browse files Browse the repository at this point in the history
Fix the PHP warning and hide the form until a list is selected in the settings.
  • Loading branch information
dkotter committed Sep 16, 2024
2 parents cd3a3fc + f57f059 commit 032b949
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/mailchimp/mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ public function post( $endpoint, $body, $method = 'POST' ) {
foreach ( $merges as $merge ) {
if ( empty( $body['errors'] ) ) {
// Email address doesn't come back from the API, so if something's wrong, it's that.
$field_name = 'Email Address';
$body['errors'][0]['message'] = 'Please fill out a valid email address.';
} elseif ( $merge['tag'] === $body['errors'][0]['field'] ) {
$field_name = esc_html__( 'Email Address', 'mailchimp' );
$body['errors'][0]['message'] = esc_html__( 'Please fill out a valid email address.', 'mailchimp' );
} elseif ( ! empty( $body['errors'] ) && isset( $body['errors'][0]['field'] ) && $merge['tag'] === $body['errors'][0]['field'] ) {
$field_name = $merge['name'];
}
}
Expand Down
4 changes: 2 additions & 2 deletions mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function mailchimp_sf_request_handler() {
}

// erase auth information
$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' );
$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' );
mailchimp_sf_delete_options( $options );
break;
case 'change_form_settings':
Expand Down Expand Up @@ -1403,5 +1403,5 @@ function mailchimp_sf_get_access_token() {
* @return bool
*/
function mailchimp_sf_should_display_form() {
return mailchimp_sf_get_api() && ! get_option( 'mailchimp_sf_auth_error' );
return mailchimp_sf_get_api() && ! get_option( 'mailchimp_sf_auth_error' ) && get_option( 'mc_list_id' );
}
15 changes: 12 additions & 3 deletions views/setup_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

// If we have an API Key, see if we need to change the lists and its options
mailchimp_sf_change_list_if_necessary();

$is_list_selected = false;
?>
<div class="wrap">
<hr class="wp-header-end" />
Expand Down Expand Up @@ -76,7 +78,15 @@
</div>
<?php
} else {
$lists = $lists['lists'];
$lists = $lists['lists'];
$option = get_option( 'mc_list_id' );
$list_ids = array_map(
function ( $ele ) {
return $ele['id'];
},
$lists
);
$is_list_selected = in_array( $option, $list_ids, true );
?>
<table class="mc-list-select" cellspacing="0">
<tr class="mc-list-row">
Expand All @@ -86,7 +96,6 @@
<option value=""> &mdash; <?php esc_html_e( 'Select A List', 'mailchimp' ); ?> &mdash; </option>
<?php
foreach ( $lists as $list ) {
$option = get_option( 'mc_list_id' );
?>
<option value="<?php echo esc_attr( $list['id'] ); ?>"<?php selected( $list['id'], $option ); ?>><?php echo esc_html( $list['name'] ); ?></option>
<?php
Expand All @@ -110,7 +119,7 @@

<?php
// Just get out if nothing else matters...
if ( get_option( 'mc_list_id' ) === '' ) {
if ( ! $is_list_selected ) {
return;
}

Expand Down

0 comments on commit 032b949

Please sign in to comment.