| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; |
| 3 |
|
| 4 |
class Pressable extends berqIntegrations { |
| 5 |
|
| 6 |
function __construct() { |
| 7 |
add_action('berqwp_flush_all_cache', [$this, 'flush_cache']); |
| 8 |
add_action('berqwp_stored_page_cache', [$this, 'flush_page_cache']); |
| 9 |
add_action('berqwp_flush_page_cache', [$this, 'flush_cache']); |
| 10 |
add_action('init', [$this, 'bypass_cache']); |
| 11 |
} |
| 12 |
|
| 13 |
function bypass_cache() { |
| 14 |
if (!$this->is_pressable()) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
$bypass_cache = apply_filters( 'berqwp_bypass_cache', false ); |
| 19 |
|
| 20 |
if ($bypass_cache) { |
| 21 |
berqReverseProxyCache::bypass(); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
function is_pressable() { |
| 26 |
return isset($_SERVER["PRESSABLE_PROXIED_REQUEST"]) || strpos(gethostname(), "atomicsites.net") !== false; |
| 27 |
} |
| 28 |
|
| 29 |
function flush_cache() { |
| 30 |
|
| 31 |
if (!$this->is_pressable()) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
wp_cache_flush(); |
| 36 |
berqReverseProxyCache::flush_all(); |
| 37 |
} |
| 38 |
|
| 39 |
function flush_page_cache($slug) { |
| 40 |
|
| 41 |
if (!$this->is_pressable()) { |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
if (empty($slug)) { |
| 46 |
$slug = '/'; |
| 47 |
} |
| 48 |
|
| 49 |
berqReverseProxyCache::purge_cache(home_url($slug)); |
| 50 |
} |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
new Pressable(); |