Skip to content

Commit

Permalink
Clear Mailchimp list ID on login if list is not available under accou…
Browse files Browse the repository at this point in the history
…nt (ie. login with different user)
  • Loading branch information
iamdharmesh committed Oct 2, 2024
1 parent cc4c225 commit de76059
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion includes/class-mailchimp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,23 @@ public function verify_and_save_oauth_token( $access_token, $data_center ) {
update_option( 'mailchimp_sf_access_token', $data_encryption->encrypt( $access_token ) );
update_option( 'mc_datacenter', sanitize_text_field( $data_center ) );
update_option( 'mc_user', $this->sanitize_data( $user ) );
return true;

// Clear Mailchimp List ID if saved list is not available.
$lists = $api->get( 'lists', 100, array( 'fields' => 'lists.id' ) );
if ( ! is_wp_error( $lists ) ) {
$lists = $lists['lists'] ?? array();
$saved_list_id = get_option( 'mc_list_id' );
$list_ids = array_map(
function ( $ele ) {
return $ele['id'];
},
$lists
);
if ( ! in_array( $saved_list_id, $list_ids, true ) ) {
delete_option( 'mc_list_id' );
}
}
return true;
} else {
$msg = esc_html__( 'API Key must belong to "Owner", "Admin", or "Manager."', 'mailchimp' );
return new WP_Error( 'mailchimp-sf-invalid-role', $msg );
Expand Down

0 comments on commit de76059

Please sign in to comment.