From 1198ebb147414b62d2255ade9557f25603fc03d3 Mon Sep 17 00:00:00 2001 From: Dharmesh Patel Date: Wed, 7 Aug 2024 23:37:41 +0530 Subject: [PATCH] Show notice for re-connect incase of token decryption fail. --- mailchimp.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mailchimp.php b/mailchimp.php index ab9db62..de7d340 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -1415,8 +1415,18 @@ function mailchimp_sf_create_nonce( $action = -1 ) { * @return string|bool */ function mailchimp_sf_get_access_token() { - $access_token = get_option( 'mailchimp_sf_access_token' ); + $access_token = get_option( 'mailchimp_sf_access_token' ); + if ( empty( $access_token ) ) { + return false; + } + $data_encryption = new Mailchimp_Data_Encryption(); + $access_token = $data_encryption->decrypt( $access_token ); + + // If decryption fails, display notice to user to re-authenticate. + if ( false === $access_token ) { + update_option( 'mailchimp_sf_auth_error', true ); + } - return $data_encryption->decrypt( $access_token ); + return $access_token; }