diff --git a/CHANGELOG.md b/CHANGELOG.md index 153b75dd..28d5e04e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This is an alpha version! The changes listed here are not final. ### Added +- Super Cache: modify boost install code so it can be used by multiple buttons - Super Cache: notify Boost of migration to that plugin ### Changed diff --git a/inc/boost.php b/inc/boost.php index 533e4046..ea3bf37e 100644 --- a/inc/boost.php +++ b/inc/boost.php @@ -1,5 +1,16 @@ wp_nonce_url( admin_url( 'update.php?action=install-plugin&plugin=jetpack-boost' ), 'install-plugin_jetpack-boost' ), + 'activate_url' => admin_url( 'plugins.php' ), + 'is_installed' => wpsc_is_boost_installed(), + ); +} + /** * 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. diff --git a/js/admin.js b/js/admin.js index eb1268ca..7d1715a1 100644 --- a/js/admin.js +++ b/js/admin.js @@ -24,7 +24,8 @@ jQuery( document ).ready( () => { } ); // One-click install for Boost. - jQuery( '#wpsc-install-boost-button' ).on( 'click', event => { + jQuery( '.wpsc-install-boost-button' ).on( 'click', event => { + const source = jQuery( event.currentTarget ).attr( 'data-source' ); event.preventDefault(); showBoostBannerBusy( __( 'Installing…', 'wp-super-cache' ) ); @@ -36,7 +37,7 @@ jQuery( document ).ready( () => { } ) .done( response => { if ( response.success ) { - activateBoost(); + activateBoost( source ); } else { showBoostBannerError( response.data ); } @@ -53,9 +54,10 @@ jQuery( document ).ready( () => { } ); // Handle activate button click. - jQuery( '#wpsc-activate-boost-button' ).on( 'click', event => { + jQuery( '.wpsc-activate-boost-button' ).on( 'click', event => { + const source = jQuery( event.currentTarget ).attr( 'data-source' ); event.preventDefault(); - activateBoost(); + activateBoost( source ); } ); // Helper function to show Boost Banner work in progress. @@ -89,13 +91,14 @@ jQuery( document ).ready( () => { }; // Activate Jetpack Boost. - const activateBoost = () => { + const activateBoost = source => { showBoostBannerBusy( __( 'Activating…', 'wp-super-cache' ) ); jQuery .post( ajaxurl, { action: 'wpsc_activate_boost', _ajax_nonce: wpscAdmin.boostActivateNonce, + source: source, } ) .done( response => { if ( response.success ) { diff --git a/wp-cache.php b/wp-cache.php index 7ee2dac4..352bacc9 100644 --- a/wp-cache.php +++ b/wp-cache.php @@ -371,11 +371,18 @@ function wpsc_hide_boost_banner() { function wpsc_ajax_activate_boost() { check_ajax_referer( 'activate-boost' ); + if ( ! isset( $_POST['source'] ) ) { + wp_send_json_error( 'no source specified' ); + } + + $source = sanitize_text_field( wp_unslash( $_POST['source'] ) ); $result = activate_plugin( 'jetpack-boost/jetpack-boost.php' ); if ( is_wp_error( $result ) ) { wp_send_json_error( $result->get_error_message() ); } + wpsc_notify_migration_to_boost( $source ); + wp_send_json_success(); } add_action( 'wp_ajax_wpsc_activate_boost', 'wpsc_ajax_activate_boost' ); @@ -390,12 +397,10 @@ function wpsc_jetpack_boost_install_banner() { return; } - $install_url = wp_nonce_url( admin_url( 'update.php?action=install-plugin&plugin=jetpack-boost' ), 'install-plugin_jetpack-boost' ); - $activate_url = admin_url( 'plugins.php' ); - $is_installed = wpsc_is_boost_installed(); - $button_url = $is_installed ? $activate_url : $install_url; - $button_label = $is_installed ? __( 'Activate Jetpack Boost', 'wp-super-cache' ) : __( 'Install Jetpack Boost', 'wp-super-cache' ); - $button_id = $is_installed ? 'wpsc-activate-boost-button' : 'wpsc-install-boost-button'; + $config = wpsc_get_boost_migration_config(); + $button_url = $config['is_installed'] ? $config['activate_url'] : $config['install_url']; + $button_label = $config['is_installed'] ? __( 'Activate Jetpack Boost', 'wp-super-cache' ) : __( 'Install Jetpack Boost', 'wp-super-cache' ); + $button_class = $config['is_installed'] ? 'wpsc-activate-boost-button' : 'wpsc-install-boost-button'; $plugin_url = plugin_dir_url( __FILE__ ); ?> @@ -419,7 +424,7 @@ function wpsc_jetpack_boost_install_banner() { - + @@ -2078,7 +2083,6 @@ function wpsc_config_file_notices() { echo '

' . $msg . '

'; } add_action( 'admin_notices', 'wpsc_config_file_notices' ); - function wpsc_dismiss_indexhtml_warning() { check_ajax_referer( "wpsc-index-dismiss" ); update_site_option( 'wp_super_cache_index_detected', 3 ); @@ -2799,7 +2803,7 @@ function wp_cache_clean_legacy_files( $dir, $file_prefix ) { @unlink( $dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); } else { $meta = json_decode( wp_cache_get_legacy_cache( $dir . 'meta/' . $file ), true ); - if ( $curr_blog_id && $curr_blog_id !== (int)$meta['blog_id'] ) { + if ( $curr_blog_id && $curr_blog_id !== (int) $meta['blog_id'] ) { continue; } @unlink( $dir . $file);