Version Description
- New Feature: Compatibility with Vimexx
- Improvement: Make some of NitroPack's requests even lighter weight
- Bug fix: Resolve an issue which was preventing some admin actions from functioning correctly
Download this release
Release Info
Developer | nitropack |
Plugin | NitroPack |
Version | 1.5.7 |
Comparing to | |
See all releases |
Code changes from version 1.5.6 to 1.5.7
- classes/Integration.php +51 -17
- classes/Integration/Hosting/Flywheel.php +1 -35
- classes/Integration/Hosting/GoDaddyWPaaS.php +1 -1
- classes/Integration/Hosting/Hosting.php +2 -4
- classes/Integration/Hosting/Kinsta.php +1 -1
- classes/Integration/Hosting/Pagely.php +2 -0
- classes/Integration/Hosting/SiteGround.php +1 -1
- classes/Integration/Hosting/Vimexx.php +45 -0
- classes/Integration/Hosting/WPEngine.php +17 -4
- classes/Integration/Plugin/Cloudflare.php +2 -0
- classes/Integration/Plugin/NginxHelper.php +12 -4
- classes/Integration/Server/LiteSpeed.php +2 -2
- constants.php +1 -1
- functions.php +31 -22
- integrations.php +0 -4
- main.php +8 -1
- readme.txt +6 -1
classes/Integration.php
CHANGED
@@ -3,11 +3,15 @@
|
|
3 |
namespace NitroPack;
|
4 |
|
5 |
class Integration {
|
|
|
|
|
|
|
6 |
private static $instance = NULL;
|
7 |
private static $purgeAllPending = false;
|
8 |
private static $purgeUrlPending = [];
|
9 |
private static $isInitialized = false;
|
10 |
private static $isInitializedStage = [];
|
|
|
11 |
private static $modules = [
|
12 |
"NitroPack/Integration/Hosting/Cloudways",
|
13 |
"NitroPack/Integration/Hosting/Flywheel",
|
@@ -16,6 +20,7 @@ class Integration {
|
|
16 |
"NitroPack/Integration/Hosting/GoDaddyWPaaS",
|
17 |
"NitroPack/Integration/Hosting/Kinsta",
|
18 |
"NitroPack/Integration/Hosting/Pagely",
|
|
|
19 |
"NitroPack/Integration/Server/LiteSpeed",
|
20 |
"NitroPack/Integration/Server/Fastly",
|
21 |
"NitroPack/Integration/Server/Cloudflare",
|
@@ -39,6 +44,28 @@ class Integration {
|
|
39 |
return self::$instance;
|
40 |
}
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
public function __construct() {
|
43 |
$this->siteConfig = nitropack_get_site_config();
|
44 |
}
|
@@ -52,17 +79,32 @@ class Integration {
|
|
52 |
|
53 |
add_action( 'nitropack_integration_purge_url', [$this, "logUrlPurge"] );
|
54 |
add_action( 'nitropack_integration_purge_all', [$this, "logFullPurge"] );
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
$this->initModules(); // very_early init
|
58 |
|
59 |
-
$action = $this->getSetupAction();
|
60 |
if (did_action($action)) {
|
61 |
$this->initModules();
|
62 |
} else {
|
63 |
add_action($action, [$this, 'initModules']);
|
64 |
}
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
self::$isInitialized = true;
|
67 |
}
|
68 |
|
@@ -88,28 +130,20 @@ class Integration {
|
|
88 |
|
89 |
self::$isInitializedStage[self::$stage] = true;
|
90 |
|
|
|
|
|
|
|
|
|
91 |
if (self::$stage == "very_early") {
|
92 |
self::$stage = "early";
|
93 |
-
} else if (self::$stage == "early") {
|
94 |
-
if ($this->siteConfig && empty($this->siteConfig["isLateIntegrationInitRequired"])) {
|
95 |
-
do_action(NITROPACK_INTEGRATIONS_ACTION);
|
96 |
-
}
|
97 |
-
|
98 |
-
// This is needed in order to load non-cache-related integrations like the one with ShortPixel and WooCommerce Geo Location.
|
99 |
-
if (did_action('plugins_loaded')) {
|
100 |
-
$this->lateInitModules();
|
101 |
-
} else {
|
102 |
-
add_action('plugins_loaded', [$this, 'lateInitModules']);
|
103 |
-
}
|
104 |
-
} else {
|
105 |
-
if ($this->siteConfig && !empty($this->siteConfig["isLateIntegrationInitRequired"])) {
|
106 |
-
do_action(NITROPACK_INTEGRATIONS_ACTION);
|
107 |
-
}
|
108 |
}
|
109 |
}
|
110 |
|
111 |
public function lateInitModules() {
|
112 |
self::$stage = "late";
|
|
|
|
|
|
|
113 |
$this->initModules();
|
114 |
}
|
115 |
|
3 |
namespace NitroPack;
|
4 |
|
5 |
class Integration {
|
6 |
+
const CRITICAL_INIT_ACTION = "nitropack_integration_critical_init";
|
7 |
+
public static $criticalInitSemaphore = 0;
|
8 |
+
|
9 |
private static $instance = NULL;
|
10 |
private static $purgeAllPending = false;
|
11 |
private static $purgeUrlPending = [];
|
12 |
private static $isInitialized = false;
|
13 |
private static $isInitializedStage = [];
|
14 |
+
private static $shutdownCallbacks = [];
|
15 |
private static $modules = [
|
16 |
"NitroPack/Integration/Hosting/Cloudways",
|
17 |
"NitroPack/Integration/Hosting/Flywheel",
|
20 |
"NitroPack/Integration/Hosting/GoDaddyWPaaS",
|
21 |
"NitroPack/Integration/Hosting/Kinsta",
|
22 |
"NitroPack/Integration/Hosting/Pagely",
|
23 |
+
"NitroPack/Integration/Hosting/Vimexx",
|
24 |
"NitroPack/Integration/Server/LiteSpeed",
|
25 |
"NitroPack/Integration/Server/Fastly",
|
26 |
"NitroPack/Integration/Server/Cloudflare",
|
44 |
return self::$instance;
|
45 |
}
|
46 |
|
47 |
+
public static function onCriticalInit($callback) {
|
48 |
+
if (!did_action(self::CRITICAL_INIT_ACTION)) {
|
49 |
+
add_action(self::CRITICAL_INIT_ACTION, $callback);
|
50 |
+
} else {
|
51 |
+
$callback();
|
52 |
+
}
|
53 |
+
}
|
54 |
+
|
55 |
+
public static function onShutdown($callback) {
|
56 |
+
self::$shutdownCallbacks[] = $callback;
|
57 |
+
}
|
58 |
+
|
59 |
+
public static function initSemAcquire() {
|
60 |
+
self::$criticalInitSemaphore++;
|
61 |
+
}
|
62 |
+
|
63 |
+
public static function initSemRelease() {
|
64 |
+
if (--self::$criticalInitSemaphore < 0) {
|
65 |
+
self::$criticalInitSemaphore = 0;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
|
69 |
public function __construct() {
|
70 |
$this->siteConfig = nitropack_get_site_config();
|
71 |
}
|
79 |
|
80 |
add_action( 'nitropack_integration_purge_url', [$this, "logUrlPurge"] );
|
81 |
add_action( 'nitropack_integration_purge_all', [$this, "logFullPurge"] );
|
82 |
+
self::onShutdown([$this, 'executeIntegrationPurges']);
|
83 |
+
register_shutdown_function(function() {
|
84 |
+
foreach (self::$shutdownCallbacks as $callback) {
|
85 |
+
$callback();
|
86 |
+
}
|
87 |
+
});
|
88 |
+
|
89 |
+
if ($this->siteConfig && !empty($this->siteConfig["isLateIntegrationInitRequired"])) {
|
90 |
+
self::initSemAcquire();
|
91 |
+
}
|
92 |
|
93 |
$this->initModules(); // very_early init
|
94 |
|
95 |
+
$action = $this->getSetupAction(); // can be muplugins_loaded or plugins_loaded
|
96 |
if (did_action($action)) {
|
97 |
$this->initModules();
|
98 |
} else {
|
99 |
add_action($action, [$this, 'initModules']);
|
100 |
}
|
101 |
|
102 |
+
if (did_action('plugins_loaded')) {
|
103 |
+
$this->lateInitModules();
|
104 |
+
} else {
|
105 |
+
add_action('plugins_loaded', [$this, 'lateInitModules']);
|
106 |
+
}
|
107 |
+
|
108 |
self::$isInitialized = true;
|
109 |
}
|
110 |
|
130 |
|
131 |
self::$isInitializedStage[self::$stage] = true;
|
132 |
|
133 |
+
if (self::$criticalInitSemaphore < 1 && !did_action(self::CRITICAL_INIT_ACTION)) {
|
134 |
+
do_action(self::CRITICAL_INIT_ACTION);
|
135 |
+
}
|
136 |
+
|
137 |
if (self::$stage == "very_early") {
|
138 |
self::$stage = "early";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
}
|
140 |
}
|
141 |
|
142 |
public function lateInitModules() {
|
143 |
self::$stage = "late";
|
144 |
+
if ($this->siteConfig && !empty($this->siteConfig["isLateIntegrationInitRequired"])) {
|
145 |
+
self::initSemRelease();
|
146 |
+
}
|
147 |
$this->initModules();
|
148 |
}
|
149 |
|
classes/Integration/Hosting/Flywheel.php
CHANGED
@@ -3,43 +3,9 @@
|
|
3 |
namespace NitroPack\Integration\Hosting;
|
4 |
|
5 |
class Flywheel extends Hosting {
|
6 |
-
const STAGE =
|
7 |
|
8 |
public static function detect() {
|
9 |
return defined("FLYWHEEL_PLUGIN_DIR");
|
10 |
}
|
11 |
-
|
12 |
-
public function init($stage) {
|
13 |
-
if ($this->getHosting() == "flywheel") {
|
14 |
-
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
15 |
-
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
16 |
-
}
|
17 |
-
}
|
18 |
-
|
19 |
-
public function purgeUrl($url) {
|
20 |
-
try {
|
21 |
-
$purger = new \NitroPack\SDK\Integrations\Varnish(array("127.0.0.1"), "PURGE");
|
22 |
-
$purger->purge($url);
|
23 |
-
} catch (\Exception $e) {
|
24 |
-
// Breeze exception
|
25 |
-
}
|
26 |
-
}
|
27 |
-
|
28 |
-
public function purgeAll() {
|
29 |
-
try {
|
30 |
-
if (function_exists("get_home_url")) {
|
31 |
-
$home = get_home_url();
|
32 |
-
} else {
|
33 |
-
$siteConfig = nitropack_get_site_config();
|
34 |
-
$home = "/";
|
35 |
-
if ($siteConfig && !empty($siteConfig["home_url"])) {
|
36 |
-
$home = $siteConfig["home_url"];
|
37 |
-
}
|
38 |
-
}
|
39 |
-
$purger = new \NitroPack\SDK\Integrations\Varnish(array("127.0.0.1"), "PURGE");
|
40 |
-
$purger->purge($home);
|
41 |
-
} catch (\Exception $e) {
|
42 |
-
// Exception
|
43 |
-
}
|
44 |
-
}
|
45 |
}
|
3 |
namespace NitroPack\Integration\Hosting;
|
4 |
|
5 |
class Flywheel extends Hosting {
|
6 |
+
const STAGE = NULL;
|
7 |
|
8 |
public static function detect() {
|
9 |
return defined("FLYWHEEL_PLUGIN_DIR");
|
10 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
}
|
classes/Integration/Hosting/GoDaddyWPaaS.php
CHANGED
@@ -32,7 +32,7 @@ class GoDaddyWPaaS extends Hosting {
|
|
32 |
public function purgeAll() {
|
33 |
$siteConfig = nitropack_get_site_config();
|
34 |
if ($siteConfig && !empty($siteConfig["home_url"])) {
|
35 |
-
return
|
36 |
}
|
37 |
return false;
|
38 |
}
|
32 |
public function purgeAll() {
|
33 |
$siteConfig = nitropack_get_site_config();
|
34 |
if ($siteConfig && !empty($siteConfig["home_url"])) {
|
35 |
+
return $this->purgeUrl($siteConfig["home_url"]);
|
36 |
}
|
37 |
return false;
|
38 |
}
|
classes/Integration/Hosting/Hosting.php
CHANGED
@@ -6,11 +6,9 @@ class Hosting {
|
|
6 |
protected function getHosting() {
|
7 |
$siteConfig = nitropack_get_site_config();
|
8 |
if ($siteConfig && !empty($siteConfig["hosting"])) {
|
9 |
-
|
10 |
} else {
|
11 |
-
|
12 |
}
|
13 |
-
|
14 |
-
return $hosting;
|
15 |
}
|
16 |
}
|
6 |
protected function getHosting() {
|
7 |
$siteConfig = nitropack_get_site_config();
|
8 |
if ($siteConfig && !empty($siteConfig["hosting"])) {
|
9 |
+
return $siteConfig["hosting"];
|
10 |
} else {
|
11 |
+
return NULL;
|
12 |
}
|
|
|
|
|
13 |
}
|
14 |
}
|
classes/Integration/Hosting/Kinsta.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
namespace NitroPack\Integration\Hosting;
|
4 |
|
5 |
class Kinsta extends Hosting {
|
6 |
-
const STAGE = "
|
7 |
|
8 |
public static function detect() {
|
9 |
return defined("KINSTAMU_VERSION");
|
3 |
namespace NitroPack\Integration\Hosting;
|
4 |
|
5 |
class Kinsta extends Hosting {
|
6 |
+
const STAGE = "very_early";
|
7 |
|
8 |
public static function detect() {
|
9 |
return defined("KINSTAMU_VERSION");
|
classes/Integration/Hosting/Pagely.php
CHANGED
@@ -15,8 +15,10 @@ class Pagely extends Hosting {
|
|
15 |
case "very_early":
|
16 |
add_action('nitropack_cacheable_cache_headers', [$this, 'addCacheControl']);
|
17 |
add_action('nitropack_cachehit_cache_headers', [$this, 'addCacheControl']);
|
|
|
18 |
return true;
|
19 |
case "early":
|
|
|
20 |
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
21 |
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
22 |
return true;
|
15 |
case "very_early":
|
16 |
add_action('nitropack_cacheable_cache_headers', [$this, 'addCacheControl']);
|
17 |
add_action('nitropack_cachehit_cache_headers', [$this, 'addCacheControl']);
|
18 |
+
\NitroPack\Integration::initSemAcquire();
|
19 |
return true;
|
20 |
case "early":
|
21 |
+
\NitroPack\Integration::initSemRelease();
|
22 |
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
23 |
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
24 |
return true;
|
classes/Integration/Hosting/SiteGround.php
CHANGED
@@ -43,7 +43,7 @@ class SiteGround extends Hosting {
|
|
43 |
public function purgeAll() {
|
44 |
$siteConfig = nitropack_get_site_config();
|
45 |
if ($siteConfig && !empty($siteConfig["home_url"])) {
|
46 |
-
return
|
47 |
}
|
48 |
return false;
|
49 |
}
|
43 |
public function purgeAll() {
|
44 |
$siteConfig = nitropack_get_site_config();
|
45 |
if ($siteConfig && !empty($siteConfig["home_url"])) {
|
46 |
+
return $this->purgeUrl(nitropack_trailingslashit($siteConfig["home_url"]) . "/(.*)");
|
47 |
}
|
48 |
return false;
|
49 |
}
|
classes/Integration/Hosting/Vimexx.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
namespace NitroPack\Integration\Hosting;
|
4 |
+
|
5 |
+
class Vimexx extends Hosting {
|
6 |
+
const STAGE = "very_early";
|
7 |
+
|
8 |
+
public static function detect() {
|
9 |
+
$hostname = gethostname();
|
10 |
+
return (!empty($hostname) && strpos($hostname, 'zxcs') !== false) || !empty($_SERVER['HTTP_X_ZXCS_VHOST']);
|
11 |
+
}
|
12 |
+
|
13 |
+
public function init($stage) {
|
14 |
+
if ($this->getHosting() == "vimexx") {
|
15 |
+
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
16 |
+
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
20 |
+
public function purgeUrl($url) {
|
21 |
+
try {
|
22 |
+
$http = new \NitroPack\HttpClient($url);
|
23 |
+
$http->setHeader("X-Purge-ZXCS", "true");
|
24 |
+
$http->setHeader("host-ZXCS", $_SERVER['HTTP_HOST']);
|
25 |
+
|
26 |
+
$http->fetch(false, "PURGE");
|
27 |
+
} catch (\Exception $e) {
|
28 |
+
// Exception
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
public function purgeAll() {
|
33 |
+
try {
|
34 |
+
$siteConfig = nitropack_get_site_config();
|
35 |
+
|
36 |
+
if(!empty($siteConfig['home_url'])) {
|
37 |
+
$homepage = $siteConfig['home_url'];
|
38 |
+
$this->purgeUrl(nitropack_trailingslashit($homepage) . '?purgeAll');
|
39 |
+
}
|
40 |
+
} catch (\Exception $e) {
|
41 |
+
// Exception
|
42 |
+
}
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
classes/Integration/Hosting/WPEngine.php
CHANGED
@@ -3,16 +3,29 @@
|
|
3 |
namespace NitroPack\Integration\Hosting;
|
4 |
|
5 |
class WPEngine extends Hosting {
|
6 |
-
const STAGE = "
|
|
|
|
|
|
|
|
|
7 |
|
8 |
public static function detect() {
|
9 |
return !!getenv('IS_WPE');
|
10 |
}
|
11 |
|
12 |
public function init($stage) {
|
13 |
-
if (
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
}
|
18 |
|
3 |
namespace NitroPack\Integration\Hosting;
|
4 |
|
5 |
class WPEngine extends Hosting {
|
6 |
+
const STAGE = "very_early";
|
7 |
+
|
8 |
+
private $urlPurges = [];
|
9 |
+
private $fullPurge = false;
|
10 |
+
private $readyToPurge = false;
|
11 |
|
12 |
public static function detect() {
|
13 |
return !!getenv('IS_WPE');
|
14 |
}
|
15 |
|
16 |
public function init($stage) {
|
17 |
+
if (self::detect()) {
|
18 |
+
switch ($stage) {
|
19 |
+
case "very_early":
|
20 |
+
define("NITROPACK_USE_MICROTIMEOUT", 20000);
|
21 |
+
\NitroPack\Integration::initSemAcquire();
|
22 |
+
return true;
|
23 |
+
case "early":
|
24 |
+
\NitroPack\Integration::initSemRelease();
|
25 |
+
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
26 |
+
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
27 |
+
break;
|
28 |
+
}
|
29 |
}
|
30 |
}
|
31 |
|
classes/Integration/Plugin/Cloudflare.php
CHANGED
@@ -25,8 +25,10 @@ class Cloudflare {
|
|
25 |
add_action('nitropack_cacheable_cache_headers', [$this, 'allowApoCache'], PHP_INT_MAX);
|
26 |
add_action('nitropack_cachehit_cache_headers', [$this, 'allowApoCache'], PHP_INT_MAX);
|
27 |
}
|
|
|
28 |
return true;
|
29 |
case "late":
|
|
|
30 |
if (self::isApoActive()) {
|
31 |
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
32 |
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
25 |
add_action('nitropack_cacheable_cache_headers', [$this, 'allowApoCache'], PHP_INT_MAX);
|
26 |
add_action('nitropack_cachehit_cache_headers', [$this, 'allowApoCache'], PHP_INT_MAX);
|
27 |
}
|
28 |
+
\NitroPack\Integration::initSemAcquire();
|
29 |
return true;
|
30 |
case "late":
|
31 |
+
\NitroPack\Integration::initSemRelease();
|
32 |
if (self::isApoActive()) {
|
33 |
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
34 |
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
classes/Integration/Plugin/NginxHelper.php
CHANGED
@@ -3,16 +3,24 @@
|
|
3 |
namespace NitroPack\Integration\Plugin;
|
4 |
|
5 |
class NginxHelper {
|
6 |
-
const STAGE = "
|
7 |
|
8 |
public static function isActive() {
|
9 |
return defined('NGINX_HELPER_BASEPATH');
|
10 |
}
|
11 |
|
12 |
public function init($stage) {
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
}
|
17 |
}
|
18 |
|
3 |
namespace NitroPack\Integration\Plugin;
|
4 |
|
5 |
class NginxHelper {
|
6 |
+
const STAGE = "very_early";
|
7 |
|
8 |
public static function isActive() {
|
9 |
return defined('NGINX_HELPER_BASEPATH');
|
10 |
}
|
11 |
|
12 |
public function init($stage) {
|
13 |
+
switch ($stage) {
|
14 |
+
case "very_early":
|
15 |
+
\NitroPack\Integration::initSemAcquire();
|
16 |
+
return true;
|
17 |
+
case "late":
|
18 |
+
\NitroPack\Integration::initSemRelease();
|
19 |
+
if (self::isActive()) {
|
20 |
+
add_action('nitropack_execute_purge_url', [$this, 'purgeUrl']);
|
21 |
+
add_action('nitropack_execute_purge_all', [$this, 'purgeAll']);
|
22 |
+
}
|
23 |
+
break;
|
24 |
}
|
25 |
}
|
26 |
|
classes/Integration/Server/LiteSpeed.php
CHANGED
@@ -53,8 +53,8 @@ class LiteSpeed {
|
|
53 |
public function init($stage) {
|
54 |
return;
|
55 |
if (self::isCacheEnabled()) {
|
56 |
-
add_action('
|
57 |
-
add_action('
|
58 |
add_action('nitropack_early_cache_headers', [$this, 'setupVary']);
|
59 |
add_action('nitropack_cacheable_cache_headers', [$this, 'allowProxyCache']);
|
60 |
}
|
53 |
public function init($stage) {
|
54 |
return;
|
55 |
if (self::isCacheEnabled()) {
|
56 |
+
add_action('nitropack_integration_purge_url', [$this, 'purgeUrl']);
|
57 |
+
add_action('nitropack_integration_purge_all', [$this, 'purgeAll']);
|
58 |
add_action('nitropack_early_cache_headers', [$this, 'setupVary']);
|
59 |
add_action('nitropack_cacheable_cache_headers', [$this, 'allowProxyCache']);
|
60 |
}
|
constants.php
CHANGED
@@ -6,7 +6,7 @@ function nitropack_trailingslashit($string) {
|
|
6 |
return rtrim( $string, '/\\' ) . '/';
|
7 |
}
|
8 |
|
9 |
-
define( 'NITROPACK_VERSION', '1.5.
|
10 |
define( 'NITROPACK_OPTION_GROUP', 'nitropack' );
|
11 |
define( 'NITROPACK_DATA_DIR', nitropack_trailingslashit(WP_CONTENT_DIR) . 'nitropack' );
|
12 |
define( 'NITROPACK_CONFIG_FILE', nitropack_trailingslashit(NITROPACK_DATA_DIR) . 'config.json' );
|
6 |
return rtrim( $string, '/\\' ) . '/';
|
7 |
}
|
8 |
|
9 |
+
define( 'NITROPACK_VERSION', '1.5.7' );
|
10 |
define( 'NITROPACK_OPTION_GROUP', 'nitropack' );
|
11 |
define( 'NITROPACK_DATA_DIR', nitropack_trailingslashit(WP_CONTENT_DIR) . 'nitropack' );
|
12 |
define( 'NITROPACK_CONFIG_FILE', nitropack_trailingslashit(NITROPACK_DATA_DIR) . 'config.json' );
|
functions.php
CHANGED
@@ -183,6 +183,12 @@ function is_valid_nitropack_beacon() {
|
|
183 |
|
184 |
function nitropack_handle_beacon() {
|
185 |
global $np_originalRequestCookies;
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
$siteConfig = nitropack_get_site_config();
|
187 |
if ($siteConfig && !empty($siteConfig["siteId"]) && !empty($siteConfig["siteSecret"]) && !empty($_POST["nitroBeaconUrl"])) {
|
188 |
$url = base64_decode($_POST["nitroBeaconUrl"]);
|
@@ -196,16 +202,17 @@ function nitropack_handle_beacon() {
|
|
196 |
$hasLocalCache = $nitro->hasLocalCache(false);
|
197 |
$proxyPurgeOnly = !empty($_POST["proxyPurgeOnly"]);
|
198 |
$layout = !empty($_POST["layout"]) ? $_POST["layout"] : "default";
|
|
|
199 |
|
200 |
if (!$proxyPurgeOnly) {
|
201 |
if (!$hasLocalCache) {
|
202 |
header("X-Nitro-Beacon: FORWARD");
|
203 |
$hasCache = $nitro->hasRemoteCache($layout, false); // Download the new cache file
|
204 |
$hasLocalCache = $hasCache;
|
205 |
-
|
206 |
} else {
|
207 |
header("X-Nitro-Beacon: SKIP");
|
208 |
-
|
209 |
}
|
210 |
}
|
211 |
|
@@ -214,15 +221,27 @@ function nitropack_handle_beacon() {
|
|
214 |
$nitro->purgeProxyCache($url);
|
215 |
do_action('nitropack_integration_purge_url', $url);
|
216 |
}
|
|
|
|
|
|
|
|
|
217 |
} catch (Exception $e) {
|
218 |
// not a critical error, do nothing
|
219 |
}
|
220 |
}
|
221 |
}
|
222 |
-
|
|
|
|
|
223 |
}
|
224 |
|
225 |
function nitropack_handle_webhook() {
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
$siteConfig = nitropack_get_site_config();
|
227 |
if ($siteConfig && $siteConfig["webhookToken"] == $_GET["token"]) {
|
228 |
switch($_GET["nitroWebhook"]) {
|
@@ -268,7 +287,9 @@ function nitropack_handle_webhook() {
|
|
268 |
break;
|
269 |
}
|
270 |
}
|
271 |
-
|
|
|
|
|
272 |
}
|
273 |
|
274 |
function nitropack_sanitize_url_input($url) {
|
@@ -502,9 +523,6 @@ function nitropack_init() {
|
|
502 |
if (!nitropack_is_optimizer_request() && nitropack_passes_page_requirements()) {// This is a cacheable URL
|
503 |
add_action('wp_head', 'nitropack_print_telemetry_script');
|
504 |
}
|
505 |
-
|
506 |
-
add_action('wp_footer', 'nitropack_print_cookie_handler_script');
|
507 |
-
add_action('get_footer', 'nitropack_print_cookie_handler_script');
|
508 |
}
|
509 |
}
|
510 |
}
|
@@ -2490,6 +2508,8 @@ function nitropack_detect_hosting() {
|
|
2490 |
return "pagely";
|
2491 |
} else if (\NitroPack\Integration\Hosting\WPX::detect()) {
|
2492 |
return "wpx";
|
|
|
|
|
2493 |
} else {
|
2494 |
return "unknown";
|
2495 |
}
|
@@ -2508,23 +2528,11 @@ function nitropack_handle_request($servedFrom = "unknown") {
|
|
2508 |
$siteConfig = nitropack_get_site_config();
|
2509 |
if ( $siteConfig && null !== $nitro = get_nitropack_sdk($siteConfig["siteId"], $siteConfig["siteSecret"]) ) {
|
2510 |
if (is_valid_nitropack_webhook()) {
|
2511 |
-
|
2512 |
-
nitropack_handle_webhook();
|
2513 |
-
} else {
|
2514 |
-
add_action(NITROPACK_INTEGRATIONS_ACTION, 'nitropack_handle_webhook');
|
2515 |
-
}
|
2516 |
} else if (is_valid_nitropack_beacon()) {
|
2517 |
-
|
2518 |
-
nitropack_handle_beacon();
|
2519 |
-
} else {
|
2520 |
-
add_action(NITROPACK_INTEGRATIONS_ACTION, 'nitropack_handle_beacon');
|
2521 |
-
}
|
2522 |
} else if (is_valid_nitropack_heartbeat()) {
|
2523 |
-
|
2524 |
-
nitropack_handle_heartbeat();
|
2525 |
-
} else {
|
2526 |
-
add_action(NITROPACK_INTEGRATIONS_ACTION, 'nitropack_handle_heartbeat');
|
2527 |
-
}
|
2528 |
} else {
|
2529 |
$GLOBALS["NitroPack.instance"] = $nitro;
|
2530 |
|
@@ -2704,6 +2712,7 @@ function nitropack_cookiepath() {
|
|
2704 |
}
|
2705 |
|
2706 |
function nitropack_setcookie($name, $value, $expires = NULL, $options = []) {
|
|
|
2707 |
$cookie_options = '';
|
2708 |
$cookie_path = nitropack_cookiepath();
|
2709 |
|
183 |
|
184 |
function nitropack_handle_beacon() {
|
185 |
global $np_originalRequestCookies;
|
186 |
+
if (!defined("NITROPACK_BEACON_HANDLED")) {
|
187 |
+
define("NITROPACK_BEACON_HANDLED", 1);
|
188 |
+
} else {
|
189 |
+
return;
|
190 |
+
}
|
191 |
+
|
192 |
$siteConfig = nitropack_get_site_config();
|
193 |
if ($siteConfig && !empty($siteConfig["siteId"]) && !empty($siteConfig["siteSecret"]) && !empty($_POST["nitroBeaconUrl"])) {
|
194 |
$url = base64_decode($_POST["nitroBeaconUrl"]);
|
202 |
$hasLocalCache = $nitro->hasLocalCache(false);
|
203 |
$proxyPurgeOnly = !empty($_POST["proxyPurgeOnly"]);
|
204 |
$layout = !empty($_POST["layout"]) ? $_POST["layout"] : "default";
|
205 |
+
$output = "";
|
206 |
|
207 |
if (!$proxyPurgeOnly) {
|
208 |
if (!$hasLocalCache) {
|
209 |
header("X-Nitro-Beacon: FORWARD");
|
210 |
$hasCache = $nitro->hasRemoteCache($layout, false); // Download the new cache file
|
211 |
$hasLocalCache = $hasCache;
|
212 |
+
$output = sprintf("Cache %s", $hasCache ? "fetched" : "requested");
|
213 |
} else {
|
214 |
header("X-Nitro-Beacon: SKIP");
|
215 |
+
$output = sprintf("Cache exists already");
|
216 |
}
|
217 |
}
|
218 |
|
221 |
$nitro->purgeProxyCache($url);
|
222 |
do_action('nitropack_integration_purge_url', $url);
|
223 |
}
|
224 |
+
|
225 |
+
\NitroPack\Integration::onShutdown(function() use ($output) {
|
226 |
+
echo $output;
|
227 |
+
});
|
228 |
} catch (Exception $e) {
|
229 |
// not a critical error, do nothing
|
230 |
}
|
231 |
}
|
232 |
}
|
233 |
+
\NitroPack\Integration::onCriticalInit(function() {
|
234 |
+
exit;
|
235 |
+
});
|
236 |
}
|
237 |
|
238 |
function nitropack_handle_webhook() {
|
239 |
+
if (!defined("NITROPACK_WEBHOOK_HANDLED")) {
|
240 |
+
define("NITROPACK_WEBHOOK_HANDLED", 1);
|
241 |
+
} else {
|
242 |
+
return;
|
243 |
+
}
|
244 |
+
|
245 |
$siteConfig = nitropack_get_site_config();
|
246 |
if ($siteConfig && $siteConfig["webhookToken"] == $_GET["token"]) {
|
247 |
switch($_GET["nitroWebhook"]) {
|
287 |
break;
|
288 |
}
|
289 |
}
|
290 |
+
\NitroPack\Integration::onCriticalInit(function() {
|
291 |
+
exit;
|
292 |
+
});
|
293 |
}
|
294 |
|
295 |
function nitropack_sanitize_url_input($url) {
|
523 |
if (!nitropack_is_optimizer_request() && nitropack_passes_page_requirements()) {// This is a cacheable URL
|
524 |
add_action('wp_head', 'nitropack_print_telemetry_script');
|
525 |
}
|
|
|
|
|
|
|
526 |
}
|
527 |
}
|
528 |
}
|
2508 |
return "pagely";
|
2509 |
} else if (\NitroPack\Integration\Hosting\WPX::detect()) {
|
2510 |
return "wpx";
|
2511 |
+
} else if (\NitroPack\Integration\Hosting\Vimexx::detect()) {
|
2512 |
+
return "vimexx";
|
2513 |
} else {
|
2514 |
return "unknown";
|
2515 |
}
|
2528 |
$siteConfig = nitropack_get_site_config();
|
2529 |
if ( $siteConfig && null !== $nitro = get_nitropack_sdk($siteConfig["siteId"], $siteConfig["siteSecret"]) ) {
|
2530 |
if (is_valid_nitropack_webhook()) {
|
2531 |
+
nitropack_handle_webhook();
|
|
|
|
|
|
|
|
|
2532 |
} else if (is_valid_nitropack_beacon()) {
|
2533 |
+
nitropack_handle_beacon();
|
|
|
|
|
|
|
|
|
2534 |
} else if (is_valid_nitropack_heartbeat()) {
|
2535 |
+
nitropack_handle_heartbeat();
|
|
|
|
|
|
|
|
|
2536 |
} else {
|
2537 |
$GLOBALS["NitroPack.instance"] = $nitro;
|
2538 |
|
2712 |
}
|
2713 |
|
2714 |
function nitropack_setcookie($name, $value, $expires = NULL, $options = []) {
|
2715 |
+
if (headers_sent()) return;
|
2716 |
$cookie_options = '';
|
2717 |
$cookie_path = nitropack_cookiepath();
|
2718 |
|
integrations.php
CHANGED
@@ -9,9 +9,5 @@ spl_autoload_register(function($class) {
|
|
9 |
}
|
10 |
});
|
11 |
|
12 |
-
if (\NitroPack\Integration\Hosting\WPEngine::detect()) {
|
13 |
-
define("NITROPACK_USE_MICROTIMEOUT", 20000);
|
14 |
-
}
|
15 |
-
|
16 |
$integration = NitroPack\Integration::getInstance();
|
17 |
$integration->init();
|
9 |
}
|
10 |
});
|
11 |
|
|
|
|
|
|
|
|
|
12 |
$integration = NitroPack\Integration::getInstance();
|
13 |
$integration->init();
|
main.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: NitroPack
|
4 |
Plugin URI: https://nitropack.io/platform/wordpress
|
5 |
Description: Everything you need for a fast website. Simple set up, easy to use, awesome support. Caching, Lazy Loading, Minification, Defer CSS/JS, CDN and more!
|
6 |
-
Version: 1.5.
|
7 |
Author: NitroPack LLC
|
8 |
Author URI: https://nitropack.io/
|
9 |
License: GPL2
|
@@ -71,6 +71,13 @@ add_action('wp_footer', 'nitropack_print_heartbeat_script');
|
|
71 |
add_action('admin_footer', 'nitropack_print_heartbeat_script');
|
72 |
add_action('get_footer', 'nitropack_print_heartbeat_script');
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
if ( is_admin() ) {
|
75 |
add_action( 'admin_menu', 'nitropack_menu' );
|
76 |
add_action( 'admin_init', 'register_nitropack_settings' );
|
3 |
Plugin Name: NitroPack
|
4 |
Plugin URI: https://nitropack.io/platform/wordpress
|
5 |
Description: Everything you need for a fast website. Simple set up, easy to use, awesome support. Caching, Lazy Loading, Minification, Defer CSS/JS, CDN and more!
|
6 |
+
Version: 1.5.7
|
7 |
Author: NitroPack LLC
|
8 |
Author URI: https://nitropack.io/
|
9 |
License: GPL2
|
71 |
add_action('admin_footer', 'nitropack_print_heartbeat_script');
|
72 |
add_action('get_footer', 'nitropack_print_heartbeat_script');
|
73 |
|
74 |
+
add_action('wp_footer', 'nitropack_print_cookie_handler_script');
|
75 |
+
add_action('admin_footer', 'nitropack_print_cookie_handler_script');
|
76 |
+
add_action('admin_footer', function() {
|
77 |
+
nitropack_setcookie("nitroCachedPage", 0, time() - 86400);
|
78 |
+
}); // Clear the nitroCachePage cookie
|
79 |
+
add_action('get_footer', 'nitropack_print_cookie_handler_script');
|
80 |
+
|
81 |
if ( is_admin() ) {
|
82 |
add_action( 'admin_menu', 'nitropack_menu' );
|
83 |
add_action( 'admin_init', 'register_nitropack_settings' );
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: cache,perfomance,optimize,pagespeed,lazy load,cdn,critical css,compression
|
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 5.8
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 1.5.
|
8 |
License: GNU General Public License, version 2
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -169,6 +169,11 @@ No. We’ve designed NitroPack to be a very lightweight solution that adds no CP
|
|
169 |
|
170 |
== Changelog ==
|
171 |
|
|
|
|
|
|
|
|
|
|
|
172 |
= 1.5.6 =
|
173 |
* Disable the compatibility with LiteSpeed servers as purging its cache with variation cookies isn't working per spec
|
174 |
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 5.8
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 1.5.7
|
8 |
License: GNU General Public License, version 2
|
9 |
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
169 |
|
170 |
== Changelog ==
|
171 |
|
172 |
+
= 1.5.7 =
|
173 |
+
* New Feature: Compatibility with Vimexx
|
174 |
+
* Improvement: Make some of NitroPack's requests even lighter weight
|
175 |
+
* Bug fix: Resolve an issue which was preventing some admin actions from functioning correctly
|
176 |
+
|
177 |
= 1.5.6 =
|
178 |
* Disable the compatibility with LiteSpeed servers as purging its cache with variation cookies isn't working per spec
|
179 |
|