@@ -29,6 +29,7 @@ class MailChimp_Admin {
29
29
* Initialize the class
30
30
*/
31
31
public function init () {
32
+ add_action ( 'admin_notices ' , array ( $ this , 'admin_notices ' ) );
32
33
add_action ( 'wp_ajax_mailchimp_sf_oauth_start ' , array ( $ this , 'start_oauth_process ' ) );
33
34
add_action ( 'wp_ajax_mailchimp_sf_oauth_finish ' , array ( $ this , 'finish_oauth_process ' ) );
34
35
}
@@ -124,6 +125,7 @@ public function finish_oauth_process() {
124
125
if ( $ result && ! empty ( $ result ['access_token ' ] ) && ! empty ( $ result ['data_center ' ] ) ) {
125
126
// Clean up the old data.
126
127
delete_option ( 'mailchimp_sf_access_token ' );
128
+ delete_option ( 'mailchimp_sf_auth_error ' );
127
129
delete_option ( 'mc_datacenter ' );
128
130
129
131
delete_site_transient ( 'mailchimp_sf_oauth_secret ' );
@@ -181,4 +183,31 @@ public function verify_and_save_oauth_token( $access_token, $data_center ) {
181
183
return new WP_Error ( 'mailchimp-sf-invalid-role ' , $ msg );
182
184
}
183
185
}
186
+
187
+ /**
188
+ * Display admin notices.
189
+ *
190
+ * @since x.x.x
191
+ */
192
+ public function admin_notices () {
193
+ // display a notice if the access token is invalid/revoked.
194
+ if ( get_option ( 'mailchimp_sf_auth_error ' , false ) && current_user_can ( 'manage_options ' ) && get_option ( 'mailchimp_sf_access_token ' , '' ) ) {
195
+ ?>
196
+ <div class="notice notice-warning is-dismissible">
197
+ <p>
198
+ <?php
199
+ $ message = sprintf (
200
+ /* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
201
+ __ ( '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 ' ),
202
+ '<a href=" ' . esc_url ( admin_url ( 'admin.php?page=mailchimp_sf_options ' ) ) . '"> ' ,
203
+ '</a> '
204
+ );
205
+
206
+ echo wp_kses ( $ message , array ( 'a ' => array ( 'href ' => array () ) ) );
207
+ ?>
208
+ </p>
209
+ </div>
210
+ <?php
211
+ }
212
+ }
184
213
}
0 commit comments