Skip to content

Commit

Permalink
Add notice with migrate button on settings page to migrate to oAuth a…
Browse files Browse the repository at this point in the history
…uthentiacation.
  • Loading branch information
iamdharmesh committed Oct 4, 2024
1 parent 8bf8ccf commit 76df079
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 17 deletions.
18 changes: 18 additions & 0 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,24 @@ body.toplevel_page_mailchimp_sf_options #footer-upgrade {
clear: both;
}

.migrate-to-oauth-wrapper {
margin: 1em 0;
}

.migrate-to-oauth-wrapper .button.mailchimp-sf-button {
padding: 9px 16px;
line-height: 14px;
}

.migrate-to-oauth-wrapper button.button.mailchimp-sf-button:disabled {
padding: 6px 16px;
}

.migrate-to-oauth-wrapper button.button.mailchimp-sf-button svg {
width: 20px;
height: 20px;
}

.button.mailchimp-sf-button.button-secondary.small {
background-color: transparent;
}
Expand Down
54 changes: 37 additions & 17 deletions includes/class-mailchimp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,29 +338,49 @@ public function admin_notices() {
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$current_screen = get_current_screen();

// Display a deprecation notice if the user is using an API key to connect with Mailchimp.
if ( get_option( 'mc_api_key', '' ) && ! get_option( 'mailchimp_sf_access_token', '' ) && mailchimp_sf_should_display_form() ) {
?>
<div class="notice notice-warning is-dismissible">
<p>
<?php
$message = sprintf(
/* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
__( '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' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
'</a>'
);

echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
?>
</p>
</div>
<?php

if ( $current_screen && 'toplevel_page_mailchimp_sf_options' === $current_screen->id ) {
?>
<div class="notice notice-warning">
<p>
<?php
esc_html_e( 'Heads up! It looks like you\'re using an API key to connect with Mailchimp, which is now deprecated. Please migrate to new OAuth authentication.', 'mailchimp' );
?>
</p>
<div class="migrate-to-oauth-wrapper">
<?php
// Migrate button.
$login_button_text = __( 'Migrate to OAuth authentication', 'mailchimp' );
include_once MCSF_DIR . 'includes/admin/templates/login-button.php'; // phpcs:ignore PEAR.Files.IncludingFile.UseRequireOnce
?>
</div>
</div>
<?php
} else {
?>
<div class="notice notice-warning is-dismissible">
<p>
<?php
$message = sprintf(
/* translators: Placeholders: %1$s - <a> tag, %2$s - </a> tag */
__( 'Heads up! It looks like you\'re using an API key to connect with Mailchimp, which is now deprecated. Please migrate to new OAuth authentication by clicking the "Migrate to OAuth authentication" button on the %1$splugin settings%2$s page.', 'mailchimp' ),
'<a href="' . esc_url( admin_url( 'admin.php?page=mailchimp_sf_options' ) ) . '">',
'</a>'
);

echo wp_kses( $message, array( 'a' => array( 'href' => array() ) ) );
?>
</p>
</div>
<?php
}
}

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

0 comments on commit 76df079

Please sign in to comment.