| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; |
| 3 |
|
| 4 |
class GoDaddy extends berqIntegrations { |
| 5 |
function __construct() { |
| 6 |
add_action('berqwp_flush_all_cache', [$this, 'flush_cache']); |
| 7 |
add_action('berqwp_stored_page_cache', [$this, 'flush_page_cache']); |
| 8 |
add_action('berqwp_flush_page_cache', [$this, 'flush_page_cache']); |
| 9 |
} |
| 10 |
|
| 11 |
function flush_cache() { |
| 12 |
$vip_url = $this->get_vip_url(); |
| 13 |
if (empty($vip_url)) { |
| 14 |
return; |
| 15 |
} |
| 16 |
$this->purge_request($vip_url, 'BAN', berqwp_home_url()); |
| 17 |
} |
| 18 |
|
| 19 |
function flush_page_cache($slug) { |
| 20 |
$vip_url = $this->get_vip_url(); |
| 21 |
if (empty($vip_url)) { |
| 22 |
return; |
| 23 |
} |
| 24 |
if (empty($slug)) { |
| 25 |
$slug = '/'; |
| 26 |
} |
| 27 |
$this->purge_request($vip_url, 'BAN', berqwp_home_url() . $slug); |
| 28 |
} |
| 29 |
|
| 30 |
private function get_vip_url(): string { |
| 31 |
if (!method_exists('\WPaas\Plugin', 'vip')) { |
| 32 |
return ''; |
| 33 |
} |
| 34 |
return (string) \WPaas\Plugin::vip(); |
| 35 |
} |
| 36 |
|
| 37 |
private function purge_request(string $vip_url, string $method, string $url) { |
| 38 |
$host = wp_parse_url($url, PHP_URL_HOST); |
| 39 |
$request = untrailingslashit(set_url_scheme(str_replace($host, $vip_url, $url), 'http')); |
| 40 |
|
| 41 |
wp_cache_flush(); |
| 42 |
update_option('gd_system_last_cache_flush', time()); |
| 43 |
|
| 44 |
wp_remote_request(esc_url_raw($request), [ |
| 45 |
'method' => $method, |
| 46 |
'blocking' => false, |
| 47 |
'headers' => ['Host' => $host], |
| 48 |
]); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
new GoDaddy(); |
| 53 |
|