Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the settings remain persistent between logging out of the account and logging in again. #66

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion 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', 'mc_list_id' );
$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' );
mailchimp_sf_delete_options( $options );
break;
case 'change_form_settings':
Expand Down
Loading