From 015af09e721dcbb0247a63feb5b9c2519279e3a5 Mon Sep 17 00:00:00 2001 From: Neil Gee Date: Mon, 3 Sep 2018 22:36:40 +1000 Subject: [PATCH] add cache busting class --- classes/class-fl-builder-cache-helper.php | 303 ++++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 classes/class-fl-builder-cache-helper.php diff --git a/classes/class-fl-builder-cache-helper.php b/classes/class-fl-builder-cache-helper.php new file mode 100644 index 0000000..e5a53fa --- /dev/null +++ b/classes/class-fl-builder-cache-helper.php @@ -0,0 +1,303 @@ + 'BAN', + ) ); + } + } +} +new Varnish; + +/** + * Comet Cache Plugin + */ +class Comet extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( class_exists( '\comet_cache' ) ) { + \comet_cache::clear(); + } + } +} +new Comet; + +/** + * WP Fastest Cache Plugin + */ +class Fastest extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( class_exists( '\WpFastestCache' ) ) { + global $wp_fastest_cache; + $wp_fastest_cache->deleteCache( true ); + } + } +} +new Fastest; + +/** + * Pagely + */ +class Pagely extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( class_exists( '\PagelyCachePurge' ) ) { + \PagelyCachePurge::purgeAll(); + } + } +} +new Pagely; + +/** + * Cache Enabler Plugin + */ +class CacheEnabler extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( class_exists( '\Cache_Enabler' ) ) { + \Cache_Enabler::clear_total_cache(); + } + } +} +new CacheEnabler; + +/** + * LiteSpeed Plugin + */ +class LiteSpeed extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( class_exists( '\LiteSpeed_Cache_API' ) ) { + \LiteSpeed_Cache_API::purge_all(); + } + } +} +new LiteSpeed; + +/** + * Siteground autoptimizer + */ +class SiteGround extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( function_exists( 'sg_cachepress_purge_cache' ) ) { + sg_cachepress_purge_cache(); + } + } +} +new SiteGround; + + +/** + * W3 Total Cache + */ +class W3TC extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( function_exists( 'w3tc_pgcache_flush' ) ) { + w3tc_pgcache_flush(); + } + } +} +new W3TC; + +/** + * WPEngine + */ +class WPE extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( class_exists( '\WpeCommon' ) ) { + \WpeCommon::purge_memcached(); + \WpeCommon::clear_maxcdn_cache(); + \WpeCommon::purge_varnish_cache(); + } + } +} +new WPE; + +/** + * wp-super-cache + */ +class SuperCache extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( function_exists( 'wp_cache_clear_cache' ) ) { + wp_cache_clear_cache(); + } + } +} +new SuperCache; + +/** + * Autooptimixze plugin. + */ +class AutoOptimize extends CacheHelper { + + function __construct() { + add_action( 'fl_builder_init_ui', array( $this, 'filters' ) ); + add_action( 'fl_builder_cache_cleared', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_layout', array( $this, 'clear_cache' ) ); + add_action( 'fl_builder_after_save_user_template', array( $this, 'clear_cache' ) ); + add_action( 'upgrader_process_complete', array( $this, 'clear_cache' ) ); + } + + function clear_cache() { + if ( class_exists( '\autoptimizeCache' ) ) { + \autoptimizeCache::clearall(); + } + } + + function filters() { + add_filter( 'autoptimize_filter_noptimize', '__return_true' ); + } +} +new AutoOptimize; + +/** + * Defines for various cache plugins that respect them. + */ +class Defines extends CacheHelper { + function __construct() { + add_action( 'fl_builder_init_ui', array( $this, 'defines' ) ); + } + + function defines() { + $this->define( 'DONOTMINIFY' ); + $this->define( 'DONOTCACHEPAGE' ); + } + +} +new Defines;