It is quite common to have CSS or JS problems after updating plugins when you keep a cache solution to increase its speed.

Auto purge WordPress cache

As part of my professional activity in the Whodunit agency, we have developed a micro plugin that automatically deletes the cache on a plugin update. Compatible with plugins:

  • Wp-Rocket in three steps:
    • cache purge,
    • removal of minified CSS & JS data,
    • and reload the cache via sitemap
  • WPEngine
  • W3 Total Cache
  • SiteGround
<?php 
/**
* Plugin Name: MyWP Auto-purge Rocket Cache
* Description: This plugin processes automatic cache purge/preload and JS/CSS minification when plugins are updated.
* Author: Magali
* Author URI: https://magali-colas.fr
* Version: 0.1
* License: GNU General Public License v3 or later
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

function mc_auto_purge_rocket_cache( $upgrader_object, $options ) {

// Begin Rocket 
// Purge Rocket cache
if ( function_exists( 'rocket_clean_domain' ) ) {
rocket_clean_domain();
}
// Clear minified CSS and JavaScript files.
if ( function_exists( 'rocket_clean_minify' ) ) {
rocket_clean_minify();
}
// Preload cache.
if ( function_exists( 'run_rocket_sitemap_preload' ) ) {
run_rocket_sitemap_preload();
}
// End rocket

// wp-super-cache
if ( function_exists( 'wp_cache_clear_cache' ) ) {
wp_cache_clear_cache();
}

// WPEngine
if ( class_exists( 'WpeCommon' ) ) {
WpeCommon::purge_memcached();
WpeCommon::clear_maxcdn_cache();
WpeCommon::purge_varnish_cache();
}

// w3 total cash
if ( function_exists( 'w3tc_pgcache_flush' ) ) {
w3tc_pgcache_flush();
}

// siteground
if ( function_exists( 'sg_cachepress_purge_cache' ) ) {
sg_cachepress_purge_cache();
}

}
add_action( 'upgrader_process_complete', 'mc_auto_purge_rocket_cache', 10, 2);
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Commentaires
Oldest
Newest Most Voted
Inline Feedbacks
View all comments