Skip to content

Commit

Permalink
Merge branch 'add/super-cache/admin-notice-boost' of github.com:Autom…
Browse files Browse the repository at this point in the history
…attic/jetpack into add/super-cache/admin-notice-boost
  • Loading branch information
donnchawp committed Jun 18, 2024
2 parents 1ac3a62 + 3fbff69 commit d1e11df
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Super Cache: add an admin notice to encourage migration to Jetpack Boost
46 changes: 45 additions & 1 deletion projects/plugins/super-cache/inc/boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,50 @@ function wpsc_get_boost_migration_config() {
);
}

/**
* Display an admin notice to install Jetpack Boost.
*/
function wpsc_jetpack_boost_notice() {
// Don't show the banner if Boost is installed, or the banner has been dismissed.
$is_dismissed = '1' === get_user_option( 'wpsc_dismissed_boost_admin_notice' );
if ( $is_dismissed ) {
return;
}

$config = wpsc_get_boost_migration_config();
$button_url = $config['is_installed'] ? $config['activate_url'] : $config['install_url'];
$button_class = $config['is_installed'] ? 'wpsc-activate-boost-button' : 'wpsc-install-boost-button';

?>
<div id="wpsc-notice-boost-migrate" class="notice boost-notice notice-success is-dismissible">
<h3>
<?php esc_html_e( 'Migrate to Jetpack Boost', 'wp-super-cache' ); ?>
</h3>
<p>
<?php esc_html_e( 'Your WP Super Cache setup is compatible with Boost\'s new caching feature. Continue to cache as you currently do and enhance your site\'s speed using our highly-rated performance solutions.', 'wp-super-cache' ); ?>
</p>

<p>
<a data-source='notice' class='button button-primary <?php echo esc_attr( $button_class ); ?>' href="<?php echo esc_url( $button_url ); ?>">
<span>
<?php esc_html_e( 'Migrate now', 'wp-super-cache' ); ?>
</span>
</a>
</p>
</div>
<?php
}
if ( isset( $_GET['page'] ) && $_GET['page'] === 'wpsupercache' ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
add_action( 'admin_notices', 'wpsc_jetpack_boost_notice' );
}

function wpsc_dismiss_boost_notice() {
check_ajax_referer( 'wpsc_dismiss_boost_notice', 'nonce' );
update_user_option( get_current_user_id(), 'wpsc_dismissed_boost_admin_notice', '1' );
wp_die();
}
add_action( 'wp_ajax_wpsc_dismiss_boost_notice', 'wpsc_dismiss_boost_notice' );

/**
* Add a notice to the settings page if the Jetpack Boost cache module is detected.
* The notice contains instructions on how to disable the Boost Cache module.
Expand Down Expand Up @@ -56,4 +100,4 @@ function wpsc_notify_migration_to_boost( $source ) {
return;
}
set_transient( 'jb_cache_moved_to_boost', $source, WEEK_IN_SECONDS );
}
}
9 changes: 9 additions & 0 deletions projects/plugins/super-cache/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,13 @@ jQuery( document ).ready( () => {
);
} );
};

// Dismiss admin notice
jQuery( '.boost-notice' ).on( 'click', '.notice-dismiss', event => {
event.preventDefault();
jQuery.post( ajaxurl, {
action: 'wpsc_dismiss_boost_notice',
_ajax_nonce: wpscAdmin.boostNoticeDismissNonce,
} );
} );
} );
24 changes: 18 additions & 6 deletions projects/plugins/super-cache/styling/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
Cantarell,
"Helvetica Neue",
sans-serif;
--max-container-width: 1128px;
--max-container-width: 1128px;
background-color: var(--jp-white);
}

Expand All @@ -50,12 +50,12 @@

#wpsc-callout ul,
#wpsc-callout ol,
#wpsc-callout > p:last-child {
#wpsc-callout>p:last-child {
font-size: var(--font-body-small);
}

#wpsc-dashboard > .header,
#wpsc-dashboard > .footer,
#wpsc-dashboard>.header,
#wpsc-dashboard>.footer,
#wpsc-dashboard .wpsc-body-content,
#wpsc-dashboard .wpsc-nav {
max-width: var(--max-container-width);
Expand All @@ -75,6 +75,7 @@
height: var(--icon-height);
border-radius: 7px;
}

.header .wpsc-name {
color: var(--jp-black);
font-family: var(--wpsc-header-font);
Expand Down Expand Up @@ -142,7 +143,7 @@

.footer {
--icon-height: 16px;

display: flex;
margin-top: 1em;
margin-bottom: 1em;
Expand All @@ -169,7 +170,18 @@
text-align: right;
}

.footer .automattic-airline img {
.footer .automattic-airline img {
width: 190px;
height: auto;
}

#wpsc-notice-boost-migrate {
width: 80%;
margin: 0 auto;
margin-top: 10px;

a.button.button-primary {
background-color: var(--jp-black);
color: var(--jp-white);
}
}
7 changes: 4 additions & 3 deletions projects/plugins/super-cache/wp-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ function wp_super_cache_admin_enqueue_scripts( $hook ) {
'wp-super-cache-admin',
'wpscAdmin',
array(
'boostDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_banner' ),
'boostInstallNonce' => wp_create_nonce( 'updates' ),
'boostActivateNonce' => wp_create_nonce( 'activate-boost' ),
'boostNoticeDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_notice' ),
'boostDismissNonce' => wp_create_nonce( 'wpsc_dismiss_boost_banner' ),
'boostInstallNonce' => wp_create_nonce( 'updates' ),
'boostActivateNonce' => wp_create_nonce( 'activate-boost' ),
)
);
}
Expand Down

0 comments on commit d1e11df

Please sign in to comment.