From 26aa59fc594bcf7b7727d1ed6900b82fb383f6ab Mon Sep 17 00:00:00 2001 From: abaicus Date: Tue, 9 Dec 2025 11:02:32 +0200 Subject: [PATCH 1/6] enh: adds Hummingbird compatibility [ref Codeinwp/optimole-service#1595] --- inc/compatibilities/hummingbird.php | 48 +++++++++++++++++++++++++++++ inc/manager.php | 1 + 2 files changed, 49 insertions(+) create mode 100644 inc/compatibilities/hummingbird.php diff --git a/inc/compatibilities/hummingbird.php b/inc/compatibilities/hummingbird.php new file mode 100644 index 00000000..b9bb7801 --- /dev/null +++ b/inc/compatibilities/hummingbird.php @@ -0,0 +1,48 @@ + Date: Tue, 9 Dec 2025 11:26:43 +0200 Subject: [PATCH 2/6] enh: adds Aruba Hispeed Cache compatibility [ref Codeinwp/optimole-service#1595] --- inc/compatibilities/aruba_hsc.php | 54 +++++++++++++++++++++++++++++++ inc/manager.php | 1 + 2 files changed, 55 insertions(+) create mode 100644 inc/compatibilities/aruba_hsc.php diff --git a/inc/compatibilities/aruba_hsc.php b/inc/compatibilities/aruba_hsc.php new file mode 100644 index 00000000..bf578700 --- /dev/null +++ b/inc/compatibilities/aruba_hsc.php @@ -0,0 +1,54 @@ +setPurger( AHSC_PURGER ); + $purge->purgeAll(); + } +} diff --git a/inc/manager.php b/inc/manager.php index f44f34e0..ddd76a7e 100644 --- a/inc/manager.php +++ b/inc/manager.php @@ -111,6 +111,7 @@ final class Optml_Manager { 'rocketnet', 'speedycache', 'hummingbird', + 'aruba_hsc', ]; /** * The current state of the buffer. From 28f1b0022b91f865d30057bf9732d66194562c92 Mon Sep 17 00:00:00 2001 From: abaicus Date: Tue, 9 Dec 2025 11:39:42 +0200 Subject: [PATCH 3/6] enh: adds Cache Enabler compatibility [ref Codeinwp/optimole-service#1595] --- inc/compatibilities/cache_enabler.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/inc/compatibilities/cache_enabler.php b/inc/compatibilities/cache_enabler.php index 4dd046c0..8a7ed94a 100644 --- a/inc/compatibilities/cache_enabler.php +++ b/inc/compatibilities/cache_enabler.php @@ -26,12 +26,17 @@ public function register() { add_filter( 'cache_enabler_page_contents_before_store', [ Optml_Main::instance()->manager, 'replace_content' ], PHP_INT_MAX, 1 ); - add_action( - 'optml_settings_updated', - function () { - do_action( 'cache_enabler_clear_site_cache' ); - } - ); + add_action( 'optml_settings_updated', [ $this, 'add_clear_cache_action' ] ); + add_action( 'optml_clear_cache', [ $this, 'add_clear_cache_action' ] ); + } + + /** + * Clear cache for Cache Enabler. + * + * @return void + */ + public function add_clear_cache_action() { + do_action( 'cache_enabler_clear_site_cache' ); } /** From ae1492e8f674fbc14cc8428387070cac2628576f Mon Sep 17 00:00:00 2001 From: abaicus Date: Tue, 9 Dec 2025 16:06:04 +0200 Subject: [PATCH 4/6] enh: adds Super Page Cache compatibility [ref Codeinwp/optimole-service#1595] --- inc/compatibilities/spc.php | 54 +++++++++++++++++++++++++++++++++++++ inc/manager.php | 1 + 2 files changed, 55 insertions(+) create mode 100644 inc/compatibilities/spc.php diff --git a/inc/compatibilities/spc.php b/inc/compatibilities/spc.php new file mode 100644 index 00000000..e8fd786d --- /dev/null +++ b/inc/compatibilities/spc.php @@ -0,0 +1,54 @@ + Date: Tue, 9 Dec 2025 18:43:50 +0200 Subject: [PATCH 5/6] enh: ensure single url cache is bust when a single path is invalidated --- inc/compatibilities/aruba_hsc.php | 18 +++++++++++++++-- inc/compatibilities/cache_enabler.php | 20 ++++++++++++++---- inc/compatibilities/hummingbird.php | 29 +++++++++++++++++++++++++-- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/inc/compatibilities/aruba_hsc.php b/inc/compatibilities/aruba_hsc.php index bf578700..52df8baf 100644 --- a/inc/compatibilities/aruba_hsc.php +++ b/inc/compatibilities/aruba_hsc.php @@ -40,15 +40,29 @@ public function should_load_early() { /** * Clear cache for Aruba Hispeed Cache. * + * @param string|bool $location The location to clear the cache for. If true, clear the cache globally. If a string, clear the cache for a particular url. * @return void */ - public function add_clear_cache_action() { + public function add_clear_cache_action( $location ) { if ( ! class_exists( '\ArubaSPA\HiSpeedCache\Purger\WpPurger' ) || ! defined( 'AHSC_PURGER' ) ) { return; } + // Initialize the purger. $purge = new \ArubaSPA\HiSpeedCache\Purger\WpPurger(); $purge->setPurger( AHSC_PURGER ); - $purge->purgeAll(); + + // Purge all cache when no location is provided. + if ( $location === true && method_exists( $purge, 'purgeAll' ) ) { + $purge->purgeAll(); + return; + } + + // Purge single URL based on the location parameter. + if ( ! method_exists( $purge, 'purgeUrl' ) ) { + return; + } + + $purge->purgeUrl( $location ); } } diff --git a/inc/compatibilities/cache_enabler.php b/inc/compatibilities/cache_enabler.php index 8a7ed94a..11c80991 100644 --- a/inc/compatibilities/cache_enabler.php +++ b/inc/compatibilities/cache_enabler.php @@ -26,17 +26,29 @@ public function register() { add_filter( 'cache_enabler_page_contents_before_store', [ Optml_Main::instance()->manager, 'replace_content' ], PHP_INT_MAX, 1 ); - add_action( 'optml_settings_updated', [ $this, 'add_clear_cache_action' ] ); + add_action( + 'optml_settings_updated', + function () { + do_action( 'cache_enabler_clear_site_cache' ); + } + ); + add_action( 'optml_clear_cache', [ $this, 'add_clear_cache_action' ] ); } /** - * Clear cache for Cache Enabler. + * Clear cache for Super Page Cache for Cloudflare. * + * @param string|bool $location The location to clear the cache for. If true, clear the cache globally. If a string, clear the cache for a particular url. * @return void */ - public function add_clear_cache_action() { - do_action( 'cache_enabler_clear_site_cache' ); + public function add_clear_cache_action( $location ) { + if ( $location === true ) { + do_action( 'cache_enabler_clear_site_cache' ); + return; + } + + do_action( 'cache_enabler_clear_page_cache_by_url', $location ); } /** diff --git a/inc/compatibilities/hummingbird.php b/inc/compatibilities/hummingbird.php index b9bb7801..878ea6ea 100644 --- a/inc/compatibilities/hummingbird.php +++ b/inc/compatibilities/hummingbird.php @@ -40,9 +40,34 @@ public function should_load_early() { /** * Clear cache for Hummingbird. * + * @param string|bool $location The location to clear the cache for. If true, clear the cache globally. If a string, clear the cache for a particular url. * @return void */ - public function add_clear_cache_action() { - do_action( 'wphb_clear_page_cache' ); + public function add_clear_cache_action( $location ) { + if ( ! class_exists( '\Hummingbird\Core\Utils' ) || ! method_exists( '\Hummingbird\Core\Utils', 'get_module' ) ) { + return; + } + + $page_cache = \Hummingbird\Core\Utils::get_module( 'page_cache' ); + + if ( ! $page_cache ) { + return; + } + + // Clear all cache + if ( true === $location ) { + $page_cache->clear_cache(); + return; + } + + // Clear specific URL + if ( ! is_string( $location ) || empty( $location ) ) { + return; + } + + $url_path = wp_parse_url( $location, PHP_URL_PATH ); + if ( $url_path ) { + $page_cache->clear_cache( trailingslashit( $url_path ), true ); + } } } From a1adc3efd9625165410de39c74a0857437db0a08 Mon Sep 17 00:00:00 2001 From: abaicus Date: Wed, 10 Dec 2025 11:47:56 +0200 Subject: [PATCH 6/6] chore: fix phpstan --- inc/compatibilities/hummingbird.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/compatibilities/hummingbird.php b/inc/compatibilities/hummingbird.php index 878ea6ea..1b19327d 100644 --- a/inc/compatibilities/hummingbird.php +++ b/inc/compatibilities/hummingbird.php @@ -44,7 +44,8 @@ public function should_load_early() { * @return void */ public function add_clear_cache_action( $location ) { - if ( ! class_exists( '\Hummingbird\Core\Utils' ) || ! method_exists( '\Hummingbird\Core\Utils', 'get_module' ) ) { + // @phpstan-ignore-next-line - we need to check that method exists explicitly as it might change in the future. + if ( ! class_exists( '\Hummingbird\Core\Utils' ) || ! method_exists( '\Hummingbird\Core\Utils', 'get_module' ) ) { // @phpstan-ignore-line return; }