11
11
}
12
12
13
13
/**
14
- * Class MailChimp_Admin
14
+ * Class Mailchimp_Admin
15
15
*
16
16
* @since x.x.x
17
17
*/
18
- class MailChimp_Admin {
18
+ class Mailchimp_Admin {
19
19
20
20
/**
21
21
* The OAuth base endpoint
@@ -125,11 +125,6 @@ public function finish_oauth_process() {
125
125
// Save the access token and data center.
126
126
$ result = json_decode ( $ response ['body ' ], true );
127
127
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
-
133
128
delete_site_transient ( 'mailchimp_sf_oauth_secret ' );
134
129
135
130
// Verify the token.
@@ -172,12 +167,16 @@ public function verify_and_save_oauth_token( $access_token, $data_center ) {
172
167
// Might as well set this data if we have it already.
173
168
$ valid_roles = array ( 'owner ' , 'admin ' , 'manager ' );
174
169
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 ' );
177
176
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 ) );
181
180
return true ;
182
181
183
182
} else {
@@ -192,24 +191,46 @@ public function verify_and_save_oauth_token( $access_token, $data_center ) {
192
191
* @since x.x.x
193
192
*/
194
193
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
+
195
202
// 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 ;
213
234
}
214
235
}
215
236
}
0 commit comments