Skip to content

Commit

Permalink
Add form to delete Boost cache loader script
Browse files Browse the repository at this point in the history
  • Loading branch information
donnchawp committed May 7, 2024
1 parent 6e094ca commit 862c1e1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
52 changes: 52 additions & 0 deletions projects/plugins/super-cache/inc/boost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* Handle the wpsc_delete_boost_loader action.
* Redirects to the WP Super Cache settings page after deleting the Jetpack Boost cache loader.
*/
function wpsc_handle_delete_boost_loader() {
if ( isset( $_POST['action'] ) && $_POST['action'] === 'wpsc_delete_boost_loader' ) {
check_admin_referer( 'wpsc_delete_boost_loader' );

$deleted = wpsc_delete_boost_loader();
if ( $deleted ) {
$redirect = add_query_arg( 'wpsc_boost_loader_deleted', '1' );
wp_safe_redirect( $redirect );
exit;
}
}
}

if ( isset( $_GET['page'] ) && $_GET['page'] === 'wpsupercache' && isset( $_POST['action'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
add_action( 'admin_init', 'wpsc_handle_delete_boost_loader' );
}

/**
* Add a notice to the WP Super Cache settings page if Jetpack Boost cache loader is detected.
* The notice contains a form to delete the Jetpack Boost cache loader.
*/
function wpsc_delete_boost_loader_form() {
global $wpsc_advanced_cache_filename;
?>
<div style="padding: 10px; width: 50%" class="notice notice-error"><h2><?php esc_html_e( 'Warning! Jetpack Boost Cache Detected', 'wp-super-cache' ); ?></h2>
<?php // translators: %s is the filename of the advanced-cache.php file ?>
<p><?php printf( esc_html__( 'The file %s was created by the Jetpack Boost plugin.', 'wp-super-cache' ), esc_html( $wpsc_advanced_cache_filename ) ); ?></p>
<p><?php esc_html_e( 'Please confirm that you want to use WP Super Cache instead of Jetpack Boost for caching:', 'wp-super-cache' ); ?></p>
<form method="POST">
<input type="hidden" name="action" value="wpsc_delete_boost_loader" />
<?php wp_nonce_field( 'wpsc_delete_boost_loader' ); ?>
<input type="submit" class="button button-primary" value="<?php esc_html_e( 'Use WP Super Cache for caching', 'wp-super-cache' ); ?>" class="button" />
</form>
</div>
<?php
}

/**
* Delete the Jetpack Boost cache loader.
*
* @return bool True if the cache loader was deleted, false otherwise.
*/
function wpsc_delete_boost_loader() {
global $wpsc_advanced_cache_filename;
return wp_delete_file( $wpsc_advanced_cache_filename );
}
11 changes: 2 additions & 9 deletions projects/plugins/super-cache/wp-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

require_once( __DIR__. '/inc/delete-cache-button.php');
require_once( __DIR__. '/inc/preload-notification.php');
require_once __DIR__ . '/inc/boost.php';

if ( ! function_exists( 'wp_cache_phase2' ) ) {
require_once( __DIR__. '/wp-cache-phase2.php');
Expand Down Expand Up @@ -2327,15 +2328,7 @@ function wpsc_check_advanced_cache() {

if ( false == $ret ) {
if ( $other_advanced_cache === 'BOOST' ) {
echo '<div style="width: 50%" class="notice notice-error"><h2>' . esc_html__( 'Warning! Jetpack Boost Cache Detected', 'wp-super-cache' ) . '</h2>';
// translators: %s is the filename of the advanced-cache.php file
echo '<p>' . sprintf( esc_html__( 'The file %s was created by the Jetpack Boost plugin.', 'wp-super-cache' ), esc_html( $wpsc_advanced_cache_filename ) ) . '</p>';
echo '<p>' . esc_html__( 'You can use Jetpack Boost and WP Super Cache at the same time but only if the Cache Site Pages module in Boost is disabled. To use WP Super Cache for caching:', 'wp-super-cache' ) . '</p>';
// translators: %s is a html link to the plugins page
echo '<ol><li>' . sprintf( esc_html__( 'Deactivate Jetpack Boost on the %s page.', 'wp-super-cache' ), '<a href="' . esc_url( admin_url( 'plugins.php' ) ) . '">' . esc_html__( 'Plugins', 'wp-super-cache' ) . '</a>' ) . '</li>';
echo '<li>' . esc_html__( 'Reload this page to configure WP Super Cache.', 'wp-super-cache' ) . '</li>';
echo '<li>' . esc_html__( 'Activate the Jetpack Boost plugin again.', 'wp-super-cache' ) . '</li>';
echo '</ol>';
wpsc_delete_boost_loader_form();
} elseif ( $other_advanced_cache ) {
echo '<div style="width: 50%" class="notice notice-error"><h2>' . __( 'Warning! You may not be allowed to use this plugin on your site.', 'wp-super-cache' ) . "</h2>";
echo '<p>' .
Expand Down

0 comments on commit 862c1e1

Please sign in to comment.