PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.4
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.4
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / inc / thirdparty / hosting / Cloudways.php

Cloudways.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.4, at inc/thirdparty/hosting/Cloudways.php

63 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit;
3
4 class Cloudways extends berqIntegrations {
5 function __construct() {
6 add_action('berqwp_stored_page_cache', [$this, 'flush_page_cache']);
7 add_action('berqwp_flush_page_cache', [$this, 'flush_page_cache']);
8 add_action('berqwp_flush_all_cache', [$this, 'flush_page_cache']);
9 }
10
11 function flush_page_cache($slug = '/') {
12 $page_url = trailingslashit( home_url() . $slug );
13 $this->flush_cloudways_varnish($page_url);
14 }
15
16 function flush_cloudways_varnish($url = '') {
17
18 if (!$this->is_varnish_running()) {
19 return;
20 }
21
22 if (empty($url)) {
23 $url = home_url();
24 }
25
26 $parse_url = parse_url($url);
27 $host = $parse_url['host'];
28
29 // Setup the request to purge Varnish cache
30 $ch = curl_init();
31 curl_setopt($ch, CURLOPT_URL, $url);
32 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PURGE');
33 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
34 curl_setopt($ch, CURLOPT_HTTPHEADER, [
35 "Host: $host"
36 ]);
37
38 $response = curl_exec($ch);
39 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
40 curl_close($ch);
41
42 return $httpCode === 200;
43 }
44
45 function is_varnish_running() {
46 // Check if the 'X-Varnish' or 'X-Cache' headers are present in the response headers
47 if (isset($_SERVER['HTTP_X_VARNISH']) || isset($_SERVER['HTTP_X_CACHE'])) {
48 return true;
49 }
50
51 return false;
52 }
53
54 function is_cloudways_hosting() {
55 if (isset($_SERVER['cw_allowed_ip'])) {
56 return true;
57 }
58
59 return false;
60 }
61 }
62
63 new Cloudways();