Skip to content

Commit f4ae7f4

Browse files
committed
Addressed PR feedback.
1 parent 23112f9 commit f4ae7f4

File tree

5 files changed

+57
-41
lines changed

5 files changed

+57
-41
lines changed

includes/class-mailchimp-admin.php

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
}
1212

1313
/**
14-
* Class MailChimp_Admin
14+
* Class Mailchimp_Admin
1515
*
1616
* @since x.x.x
1717
*/
18-
class MailChimp_Admin {
18+
class Mailchimp_Admin {
1919

2020
/**
2121
* The OAuth base endpoint
@@ -125,11 +125,6 @@ public function finish_oauth_process() {
125125
// Save the access token and data center.
126126
$result = json_decode( $response['body'], true );
127127
if ( $result && ! empty( $result['access_token'] ) && ! empty( $result['data_center'] ) ) {
128-
// Clean up the old data.
129-
delete_option( 'mailchimp_sf_access_token' );
130-
delete_option( 'mailchimp_sf_auth_error' );
131-
delete_option( 'mc_datacenter' );
132-
133128
delete_site_transient( 'mailchimp_sf_oauth_secret' );
134129

135130
// Verify the token.
@@ -172,12 +167,16 @@ public function verify_and_save_oauth_token( $access_token, $data_center ) {
172167
// Might as well set this data if we have it already.
173168
$valid_roles = array( 'owner', 'admin', 'manager' );
174169
if ( isset( $user['role'] ) && in_array( $user['role'], $valid_roles, true ) ) {
175-
$data_encryption = new MailChimp_Data_Encryption();
176-
$access_token = $data_encryption->encrypt( $access_token );
170+
$data_encryption = new Mailchimp_Data_Encryption();
171+
172+
// Clean up the old data.
173+
delete_option( 'mailchimp_sf_access_token' );
174+
delete_option( 'mailchimp_sf_auth_error' );
175+
delete_option( 'mc_datacenter' );
177176

178-
update_option( 'mailchimp_sf_access_token', $access_token );
179-
update_option( 'mc_datacenter', $data_center );
180-
update_option( 'mc_user', $user );
177+
update_option( 'mailchimp_sf_access_token', $data_encryption->encrypt( $access_token ) );
178+
update_option( 'mc_datacenter', sanitize_text_field( $data_center ) );
179+
update_option( 'mc_user', $this->sanitize_data( $user ) );
181180
return true;
182181

183182
} else {
@@ -192,24 +191,46 @@ public function verify_and_save_oauth_token( $access_token, $data_center ) {
192191
* @since x.x.x
193192
*/
194193
public function admin_notices() {
194+
if (
195+
! get_option( 'mailchimp_sf_auth_error', false ) ||
196+
! current_user_can( 'manage_options' ) ||
197+
! get_option( 'mailchimp_sf_access_token', '' )
198+
) {
199+
return;
200+
}
201+
195202
// display a notice if the access token is invalid/revoked.
196-
if ( get_option( 'mailchimp_sf_auth_error', false ) && current_user_can( 'manage_options' ) && get_option( 'mailchimp_sf_access_token', '' ) ) {
197-
?>
198-
<div class="notice notice-warning is-dismissible">
199-
<p>
200-
<?php
201-
$message = sprintf(
202-
/* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
203-
__( 'Heads up! There may be a problem with your connection to Mailchimp. Please %1$sre-connect%2$s your Mailchimp account to fix the issue.', 'mailchimp' ),
204-
'<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
205-
'</a>'
206-
);
207-
208-
echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
209-
?>
210-
</p>
211-
</div>
212-
<?php
203+
?>
204+
<div class="notice notice-warning is-dismissible">
205+
<p>
206+
<?php
207+
$message = sprintf(
208+
/* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
209+
__( 'Heads up! There may be a problem with your connection to Mailchimp. Please %1$sre-connect%2$s your Mailchimp account to fix the issue.', 'mailchimp' ),
210+
'<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
211+
'</a>'
212+
);
213+
214+
echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
215+
?>
216+
</p>
217+
</div>
218+
<?php
219+
}
220+
221+
/**
222+
* Sanitize variables using sanitize_text_field.
223+
*
224+
* Arrays are sanitized recursively, Non-scalar values are ignored.
225+
*
226+
* @param string|array $data Data to sanitize.
227+
* @return string|array
228+
*/
229+
public function sanitize_data( $data ) {
230+
if ( is_array( $data ) ) {
231+
return array_map( array( $this, 'sanitize_data' ), $data );
232+
} else {
233+
return is_scalar( $data ) ? sanitize_text_field( $data ) : $data;
213234
}
214235
}
215236
}

includes/class-mailchimp-data-encryption.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
}
1212

1313
/**
14-
* Class MailChimp_Data_Encryption
14+
* Class Mailchimp_Data_Encryption
1515
*
1616
* @since x.x.x
1717
*/
18-
class MailChimp_Data_Encryption {
18+
class Mailchimp_Data_Encryption {
1919

2020
/**
2121
* Key to use for encryption.

js/admin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @param {string} token - Token from the Oauth service.
1212
*/
13-
function openMailChimpOauthPopup(token) {
13+
function openMailchimpOauthPopup(token) {
1414
const startUrl = oauthBaseUrl + '/auth/start/' + token;
1515
const width = 800;
1616
const height = 600;
@@ -52,7 +52,7 @@
5252
click() {
5353
$(this).dialog('close');
5454
$(spinner).addClass('is-active');
55-
openMailChimpOauthPopup(token);
55+
openMailchimpOauthPopup(token);
5656
},
5757
style: 'margin-left: 10px;',
5858
},
@@ -134,7 +134,7 @@
134134
function (response) {
135135
if (response.success && response.data && response.data.token) {
136136
// Open Mailchimp OAuth popup.
137-
openMailChimpOauthPopup(response.data.token);
137+
openMailchimpOauthPopup(response.data.token);
138138
} else {
139139
if (response.data && response.data.message) {
140140
$(errorSelector).html(response.data.message);

mailchimp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363

6464
// Init Admin functions.
6565
require_once plugin_dir_path( __FILE__ ) . 'includes/class-mailchimp-admin.php';
66-
$admin = new MailChimp_Admin();
66+
$admin = new Mailchimp_Admin();
6767
$admin->init();
6868

6969
/**
@@ -1416,7 +1416,7 @@ function mailchimp_sf_create_nonce( $action = -1 ) {
14161416
*/
14171417
function mailchimp_sf_get_access_token() {
14181418
$access_token = get_option( 'mailchimp_sf_access_token' );
1419-
$data_encryption = new MailChimp_Data_Encryption();
1419+
$data_encryption = new Mailchimp_Data_Encryption();
14201420

14211421
return $data_encryption->decrypt( $access_token );
14221422
}

views/setup_page.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@
7272
<p class="oauth-error error_msg" style="display:none;"></p>
7373
<div id="login-popup-blocked-modal" style="display:none;">
7474
<p><?php esc_html_e( 'Please allow your browser to show popups for this page.', 'mailchimp' ); ?></p>
75-
<div class="footer">
76-
<a href="https://mailchimp.com/help/enable-pop-ups-in-your-browser/"><!--TODO: This link not working fix this. -->
77-
<?php esc_html_e( 'How to Enable Pop-ups in Your Browser', 'mailchimp' ); ?>
78-
</a>
79-
</div>
8075
</div>
8176
</div>
8277
</div>

0 commit comments

Comments
 (0)