Skip to content

Commit

Permalink
Boost: remove wp-content/advanced-cache.php when Cache module is disa…
Browse files Browse the repository at this point in the history
…bled (#37643)

* Remove advanced-cache.php when Cache module is disabled

* changelog

* Move the deactivate code into its own function

* Rename functions so they're more explicit about what they do
  • Loading branch information
donnchawp authored Jun 10, 2024
1 parent f47bed1 commit 72e08aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function __construct() {
public function setup() {
Garbage_Collection::setup();

add_action( 'jetpack_boost_module_status_updated', array( $this, 'handle_module_status_updated' ), 10, 2 );
add_action( 'jetpack_boost_module_status_updated', array( $this, 'clear_cache_on_output_changing_module_toggle' ), 10, 2 );
add_action( 'jetpack_boost_module_status_updated', array( $this, 'delete_advanced_cache' ), 10, 2 );
add_action( 'jetpack_boost_critical_css_invalidated', array( $this, 'invalidate_cache' ) );
add_action( 'jetpack_boost_critical_css_generated', array( $this, 'invalidate_cache' ) );
add_action( 'update_option_' . JETPACK_BOOST_DATASYNC_NAMESPACE . '_minify_js_excludes', array( $this, 'invalidate_cache' ) );
Expand All @@ -53,7 +54,7 @@ public function setup() {
*
* @param string $module_slug The slug of the module that was updated.
*/
public function handle_module_status_updated( $module_slug, $status ) {
public function clear_cache_on_output_changing_module_toggle( $module_slug, $status ) {
// Get a list of modules that can change the HTML output.
$output_changing_modules = Modules_Index::get_modules_implementing( Changes_Page_Output::class );

Expand All @@ -71,6 +72,15 @@ public function handle_module_status_updated( $module_slug, $status ) {
}
}

/**
* Handles the deactivation of the module by removing the advanced-cache.php file.
*/
public function delete_advanced_cache( $module_slug, $status ) {
if ( $module_slug === 'page_cache' && ! $status ) {
Page_Cache_Setup::delete_advanced_cache();
}
}

public function invalidate_cache() {
$cache = new Boost_Cache();
$cache->get_storage()->invalidate( home_url(), Filesystem_Utils::DELETE_ALL );
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Boost: remove the advanced-cache.php when the Cache module is disabled

0 comments on commit 72e08aa

Please sign in to comment.