PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.16.8
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.16.8
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / Integration / Hosting / Pressable.php
nitropack / classes / Integration / Hosting Last commit date
Closte.php 4 years ago Cloudways.php 4 years ago DreamHost.php 3 years ago Flywheel.php 4 years ago GoDaddyWPaaS.php 4 years ago GridPane.php 4 years ago Hosting.php 4 years ago Kinsta.php 2 years ago Pagely.php 2 years ago PagelyCachePurge.php 4 years ago Pantheon.php 2 years ago Pressable.php 2 years ago Raidboxes.php 2 years ago RocketNet.php 3 years ago Savvii.php 3 years ago SiteGround.php 2 years ago SpinupWp.php 2 years ago Vimexx.php 3 years ago WPEngine.php 2 years ago WPX.php 3 years ago WPmudev.php 2 years ago
Pressable.php
104 lines
1 <?php
2
3 namespace NitroPack\Integration\Hosting;
4
5 class Pressable extends Hosting {
6 const STAGE = "very_early";
7 private $deviceTypes = ["mobile", "tablet", "desktop"];
8 private $configuredCacheGroups = false;
9
10 public static function detect() {
11 return isset($_SERVER["PRESSABLE_PROXIED_REQUEST"]) || strpos(gethostname(), "atomicsites.net") !== false;
12 }
13
14 public function init($stage) {
15 if ($this->getHosting() == "pressable") {
16 switch ($stage) {
17 case "very_early":
18 $this->noCache();
19 add_action('nitropack_cacheable_cache_headers', [$this, 'cacheShort']);
20 add_action('nitropack_cachehit_cache_headers', [$this, 'cacheLong']);
21 \NitroPack\ModuleHandler::initSemAcquire();
22 return true;
23 case "early":
24 \NitroPack\ModuleHandler::initSemRelease();
25 add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
26 add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
27 return;
28 default:
29 return;
30 }
31 }
32 }
33
34 public function noCache() {
35 global $batcache;
36
37 if (!empty($batcache) && is_object($batcache)) {
38 $batcache->max_age = 0;
39 }
40 }
41
42 public function cacheShort() {
43 global $batcache;
44
45 if (!empty($batcache) && is_object($batcache)) {
46 $batcache->max_age = 30;
47 }
48 }
49
50 public function cacheLong() {
51 global $batcache;
52
53 if (!empty($batcache) && is_object($batcache)) {
54 $batcache->max_age = 300;
55 }
56 }
57
58 public function purgeUrl($url) {
59 global $batcache;
60
61 if (!$batcache || !is_object($batcache)) return;
62
63 $urlObj = new \NitroPack\Url\Url($url);
64 if ($urlObj->getHost()) {
65 parse_str($urlObj->getQuery(), $query);
66
67 foreach ($batcache->ignored_query_args as $arg) {
68 unset($query[$arg]);
69 }
70 ksort($query);
71
72 $keys = array(
73 'host' => $urlObj->getHost(),
74 'method' => "GET",
75 'path' => $urlObj->getPath(),
76 'query' => $query,
77 'extra' => []
78 );
79
80 if ( isset( $batcache->origin ) ) {
81 $keys['origin'] = $batcache->origin;
82 }
83
84 if ( $urlObj->getScheme() == "https" )
85 $keys['ssl'] = true;
86
87 wp_cache_init();
88 $batcache->configure_groups();
89
90 foreach ($this->deviceTypes as $deviceType) {
91 $keys["extra"] = [$deviceType];
92 $url_key = md5(serialize($keys));
93
94 wp_cache_delete( $url_key, $batcache->group );
95 }
96 }
97 }
98
99 public function purgeAll() {
100 wp_cache_flush();
101 }
102 }
103
104