Skip to content

Commit 44d673f

Browse files
authored
Merge pull request #67 from mailchimp/enhancement/migrate-to-oauth
Improve migration flow to new OAuth authentication for a better user experience.
2 parents df5f5f8 + 9135ab0 commit 44d673f

File tree

4 files changed

+82
-30
lines changed

4 files changed

+82
-30
lines changed

assets/css/admin.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,24 @@ body.toplevel_page_mailchimp_sf_options #footer-upgrade {
523523
clear: both;
524524
}
525525

526+
.migrate-to-oauth-wrapper {
527+
margin: 1em 0;
528+
}
529+
530+
.migrate-to-oauth-wrapper .button.mailchimp-sf-button {
531+
padding: 9px 16px;
532+
line-height: 14px;
533+
}
534+
535+
.migrate-to-oauth-wrapper button.button.mailchimp-sf-button:disabled {
536+
padding: 6px 16px;
537+
}
538+
539+
.migrate-to-oauth-wrapper button.button.mailchimp-sf-button svg {
540+
width: 20px;
541+
height: 20px;
542+
}
543+
526544
.button.mailchimp-sf-button.button-secondary.small {
527545
background-color: transparent;
528546
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Suggest to login template
4+
*
5+
* @package Mailchimp
6+
*/
7+
8+
$button_text = $login_button_text ?? __( 'Log in', 'mailchimp' );
9+
?>
10+
<button id="mailchimp_sf_oauth_connect" class="button mailchimp-sf-button">
11+
<span class="mailchimp-sf-loading hidden">
12+
<svg class="animate-spin" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
13+
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
14+
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
15+
</svg>
16+
</span>
17+
<?php echo esc_html( $button_text ); ?>
18+
</button>
19+
<p class="mailchimp-sf-oauth-error error-field" style="display:none;"></p>
20+
<div id="mailchimp-sf-popup-blocked-modal" style="display:none;">
21+
<p><?php esc_html_e( 'Please allow your browser to show popups for this page.', 'mailchimp' ); ?></p>
22+
</div>

includes/admin/templates/suggest-to-login.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,9 @@
2626
?>
2727
</p>
2828

29-
<button id="mailchimp_sf_oauth_connect" class="button mailchimp-sf-button">
30-
<span class="mailchimp-sf-loading hidden">
31-
<svg class="animate-spin" width="24" height="24" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
32-
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
33-
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
34-
</svg>
35-
</span>
36-
<?php esc_html_e( 'Log in', 'mailchimp' ); ?>
37-
</button>
38-
<p class="mailchimp-sf-oauth-error error-field" style="display:none;"></p>
39-
<div id="mailchimp-sf-popup-blocked-modal" style="display:none;">
40-
<p><?php esc_html_e( 'Please allow your browser to show popups for this page.', 'mailchimp' ); ?></p>
41-
</div>
29+
<?php
30+
// Login button.
31+
include_once MCSF_DIR . 'includes/admin/templates/login-button.php'; // phpcs:ignore PEAR.Files.IncludingFile.UseRequireOnce
32+
?>
4233
</div>
4334
</div>

includes/class-mailchimp-admin.php

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public function verify_and_save_oauth_token( $access_token, $data_center ) {
299299
$data_encryption = new Mailchimp_Data_Encryption();
300300

301301
// Clean up the old data.
302+
delete_option( 'mc_api_key' ); // Deprecated API key, need to remove as part of the migration.
302303
delete_option( 'mailchimp_sf_access_token' );
303304
delete_option( 'mailchimp_sf_auth_error' );
304305
delete_option( 'mc_datacenter' );
@@ -338,29 +339,49 @@ public function admin_notices() {
338339
if ( ! current_user_can( 'manage_options' ) ) {
339340
return;
340341
}
342+
$current_screen = get_current_screen();
341343

342344
// Display a deprecation notice if the user is using an API key to connect with Mailchimp.
343345
if ( get_option( 'mc_api_key', '' ) && ! get_option( 'mailchimp_sf_access_token', '' ) && mailchimp_sf_should_display_form() ) {
344-
?>
345-
<div class="notice notice-warning is-dismissible">
346-
<p>
347-
<?php
348-
$message = sprintf(
349-
/* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
350-
__( 'Heads up! It looks like you\'re using an API key to connect with Mailchimp, which is now deprecated. Please log out and reconnect your Mailchimp account using the new OAuth authentication by clicking the "Log in" button on the %1$splugin settings%2$s page.', 'mailchimp' ),
351-
'<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
352-
'</a>'
353-
);
354-
355-
echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
356-
?>
357-
</p>
358-
</div>
359-
<?php
346+
347+
if ( $current_screen && 'toplevel_page_mailchimp_sf_options' === $current_screen->id ) {
348+
?>
349+
<div class="notice notice-warning">
350+
<p>
351+
<?php
352+
esc_html_e( 'You are using an outdated API Key connection to Mailchimp, please migrate to the new OAuth authentication method to continue accessing your Mailchimp account.', 'mailchimp' );
353+
?>
354+
</p>
355+
<div class="migrate-to-oauth-wrapper">
356+
<?php
357+
// Migrate button.
358+
$login_button_text = __( 'Migrate to OAuth authentication', 'mailchimp' );
359+
include_once MCSF_DIR . 'includes/admin/templates/login-button.php'; // phpcs:ignore PEAR.Files.IncludingFile.UseRequireOnce
360+
?>
361+
</div>
362+
</div>
363+
<?php
364+
} else {
365+
?>
366+
<div class="notice notice-warning is-dismissible">
367+
<p>
368+
<?php
369+
$message = sprintf(
370+
/* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
371+
__( 'You are using an outdated API Key connection to Mailchimp, please migrate to the new OAuth authentication method to continue accessing your Mailchimp account by clicking the "Migrate to OAuth authentication" button on the %1$sMailchimp settings%2$s page.', 'mailchimp' ),
372+
'<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
373+
'</a>'
374+
);
375+
376+
echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
377+
?>
378+
</p>
379+
</div>
380+
<?php
381+
}
360382
}
361383

362384
// Display a notice if the user is waiting for the login to complete.
363-
$current_screen = get_current_screen();
364385
if ( $current_screen && 'toplevel_page_mailchimp_sf_options' === $current_screen->id ) {
365386
$api = mailchimp_sf_get_api();
366387
if ( $api && 'waiting' === get_option( 'mailchimp_sf_waiting_for_login' ) ) {

0 commit comments

Comments
 (0)