Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions inc/compatibilities/aruba_hsc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/**
* Class Optml_aruba_hsc.
*
* @reason Clear cache on Aruba Hispeed Cache.
*/
class Optml_aruba_hsc extends Optml_compatibility {

/**
* Should we load the integration logic.
*
* @return bool Should we load.
*/
public function should_load() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';

return is_plugin_active( 'aruba-hispeed-cache/aruba-hispeed-cache.php' );
}

/**
* Register integration details.
*
* @return void
*/
public function register() {
add_action( 'optml_clear_cache', [ $this, 'add_clear_cache_action' ] );
}


/**
* Should we early load the compatibility?
*
* @return bool Whether to load the compatibility or not.
*/
public function should_load_early() {
return true;
}

/**
* 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( $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 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 );
}
}
17 changes: 17 additions & 0 deletions inc/compatibilities/cache_enabler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ function () {
do_action( 'cache_enabler_clear_site_cache' );
}
);

add_action( 'optml_clear_cache', [ $this, 'add_clear_cache_action' ] );
}

/**
* 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( $location ) {
if ( $location === true ) {
do_action( 'cache_enabler_clear_site_cache' );
return;
}

do_action( 'cache_enabler_clear_page_cache_by_url', $location );
}

/**
Expand Down
74 changes: 74 additions & 0 deletions inc/compatibilities/hummingbird.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* Class Optml_hummingbird.
*
* @reason Clear cache on Hummingbird.
*/
class Optml_hummingbird extends Optml_compatibility {

/**
* Should we load the integration logic.
*
* @return bool Should we load.
*/
public function should_load() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';

return is_plugin_active( 'hummingbird-performance/wp-hummingbird.php' );
}

/**
* Register integration details.
*
* @return void
*/
public function register() {
add_action( 'optml_clear_cache', [ $this, 'add_clear_cache_action' ] );
}


/**
* Should we early load the compatibility?
*
* @return bool Whether to load the compatibility or not.
*/
public function should_load_early() {
return true;
}

/**
* 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( $location ) {
// @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;
}

$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 );
}
}
}
54 changes: 54 additions & 0 deletions inc/compatibilities/spc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* Class Optml_swcfpc.
*
* @reason Clear cache on Super Page Cache for Cloudflare.
*/
class Optml_spc extends Optml_compatibility {

/**
* Should we load the integration logic.
*
* @return bool Should we load.
*/
public function should_load() {
include_once ABSPATH . 'wp-admin/includes/plugin.php';

return is_plugin_active( 'wp-cloudflare-page-cache/wp-cloudflare-super-page-cache.php' ) || is_plugin_active( 'wp-super-page-cache-pro/wp-cloudflare-super-page-cache-pro.php' );
}

/**
* Register integration details.
*
* @return void
*/
public function register() {
add_action( 'optml_clear_cache', [ $this, 'add_clear_cache_action' ] );
}

/**
* Should we early load the compatibility?
*
* @return bool Whether to load the compatibility or not.
*/
public function should_load_early() {
return true;
}

/**
* 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( $location ) {
if ( is_string( $location ) ) {
do_action( 'swcfpc_purge_cache', [ $location ] );

return;
}

do_action( 'swcfpc_purge_cache' );
}
}
3 changes: 3 additions & 0 deletions inc/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ final class Optml_Manager {
'endurance_cache',
'rocketnet',
'speedycache',
'hummingbird',
'aruba_hsc',
'spc',
];
/**
* The current state of the buffer.
Expand Down
Loading