NitroPack - Version 1.5.16

Version Description

  • Improvement: Update the compatibility with SiteGround's Dynamic Cache layer
  • Bug fix: Resolve cache bypass issues on LiteSpeed
Download this release

Release Info

Developer nitropack
Plugin Icon 128x128 NitroPack
Version 1.5.16
Comparing to
See all releases

Code changes from version 1.5.15 to 1.5.16

advanced-cache.php CHANGED
@@ -39,7 +39,7 @@ if (defined("NITROPACK_VERSION") && defined("NITROPACK_ADVANCED_CACHE_VERSION")
39
  }
40
  }
41
 
42
- if ( stripos($contentType, 'text/html') !== false && nitropack_passes_cookie_requirements() && nitropack_passes_page_requirements(false)) {
43
  define("NITROPACK_BEACON_PRINTED", true);
44
  $buffer = str_replace("</body", nitropack_get_beacon_script() . "</body", $buffer);
45
  }
39
  }
40
  }
41
 
42
+ if ( stripos($contentType, 'text/html') !== false && !preg_match("/<html.*?\s(amp|⚡)(\s|=|>)/", $buffer) && nitropack_passes_cookie_requirements() && nitropack_passes_page_requirements(false)) {
43
  define("NITROPACK_BEACON_PRINTED", true);
44
  $buffer = str_replace("</body", nitropack_get_beacon_script() . "</body", $buffer);
45
  }
classes/Integration/Hosting/SiteGround.php CHANGED
@@ -24,18 +24,44 @@ class SiteGround extends Hosting {
24
 
25
  public function purgeUrl($url) {
26
  $urlObj = new \NitroPack\Url($url);
27
- $purgeUrl = $urlObj->getHost() . $urlObj->getPath();
 
 
 
28
  if ($urlObj->getQuery()) {
29
- $purgeUrl .= "(.*)";
30
  }
31
 
32
- $purgeUrl = preg_replace("/^www\./", "", $purgeUrl);
33
- $purgeUrl = "http://" . $purgeUrl;
34
-
35
  try {
36
- $hosts = ['127.0.0.1'];
37
- $purger = new \NitroPack\SDK\Integrations\Varnish($hosts, 'PURGE');
38
- $purger->purge($purgeUrl);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  } catch (\Exception $e) {}
40
 
41
  return true;
24
 
25
  public function purgeUrl($url) {
26
  $urlObj = new \NitroPack\Url($url);
27
+
28
+ $host = preg_replace("/^www\./", "", $urlObj->getHost());
29
+ $path = $urlObj->getPath();
30
+
31
  if ($urlObj->getQuery()) {
32
+ $path .= "(.*)";
33
  }
34
 
 
 
 
35
  try {
36
+ $sock_path = '/chroot/tmp/site-tools.sock';
37
+ if ( ! file_exists( $sock_path ) ) {
38
+ return false;
39
+ }
40
+
41
+ $sock = stream_socket_client( 'unix://' . $sock_path, $errno, $errstr, 5 );
42
+
43
+ if ( false === $sock ) {
44
+ return false;
45
+ }
46
+
47
+ $req = array(
48
+ 'api' => 'domain-all',
49
+ 'cmd' => 'update',
50
+ 'settings' => array( 'json' => 1 ),
51
+ 'params' => array(
52
+ 'flush_cache' => '1',
53
+ 'id' => $host,
54
+ 'path' => $path,
55
+ ),
56
+ );
57
+
58
+ fwrite( $sock, json_encode( $req, JSON_FORCE_OBJECT ) . "\n" );
59
+ $response = fgets( $sock, 32 * 1024 );
60
+ fclose( $sock );
61
+ $result = @json_decode( $response, true );
62
+ if ( false === $result || isset( $result['err_code'] ) ) {
63
+ return false;
64
+ }
65
  } catch (\Exception $e) {}
66
 
67
  return true;
classes/Integration/Server/LiteSpeed.php CHANGED
@@ -143,12 +143,31 @@ RewriteCond %{HTTP_USER_AGENT} Android.*Mobile [NC,OR]
143
  RewriteCond %{HTTP_USER_AGENT} Mobile.*Android [NC]
144
  RewriteRule .* - [E=Cache-Control:vary=nitromobile]
145
 
 
 
 
146
  # QSDROP
147
 
148
  </IfModule>
149
  ";
150
 
151
  $nitro = get_nitropack()->getSdk();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  if ($nitro && !empty($nitro->getConfig()->IgnoredParams)) {
153
  $rules = str_replace("# QSDROP", implode("\n", array_map(function($param) { return "CacheKeyModify -qs:$param"; }, array_filter($nitro->getConfig()->IgnoredParams, function($param) { return $param != "ignorenitro"; }))), $rules);
154
  }
143
  RewriteCond %{HTTP_USER_AGENT} Mobile.*Android [NC]
144
  RewriteRule .* - [E=Cache-Control:vary=nitromobile]
145
 
146
+ RewriteCond %{HTTP_COOKIE} COOKIEBYPASS
147
+ RewriteRule .* - [E=Cache-Control:no-cache]
148
+
149
  # QSDROP
150
 
151
  </IfModule>
152
  ";
153
 
154
  $nitro = get_nitropack()->getSdk();
155
+
156
+ $bypassCookies = ["wordpress_logged_in", "comment_author", "wp-postpass_", "woocommerce_items_in_cart="];
157
+ if (defined('NITROPACK_LOGGED_IN_COOKIE') || defined('LOGGED_IN_COOKIE')) {
158
+ $bypassCookies[] = (defined('NITROPACK_LOGGED_IN_COOKIE') ? NITROPACK_LOGGED_IN_COOKIE : (defined('LOGGED_IN_COOKIE') ? LOGGED_IN_COOKIE : '')) . "="; // Add "=" for exact match
159
+ }
160
+ if ($nitro && !!$nitro->getConfig()->ExcludedCookies->Status && !empty($nitro->getConfig()->ExcludedCookies->Cookies)) {
161
+ foreach ($nitro->getConfig()->ExcludedCookies->Cookies as $excludedCookie) {
162
+ if ($excludedCookie->values) {
163
+ $bypassCookies[] = $excludedCookie->name . "=(" . implode("|", $excludedCookie->values) . ')\s*(;|$)';
164
+ } else {
165
+ $bypassCookies[] = $excludedCookie->name . "=";
166
+ }
167
+ }
168
+ }
169
+ $rules = str_replace("COOKIEBYPASS", "(" . implode("|", array_map(function($cookie){ return "(^|\;\s*)$cookie"; }, $bypassCookies)) . ")", $rules);
170
+
171
  if ($nitro && !empty($nitro->getConfig()->IgnoredParams)) {
172
  $rules = str_replace("# QSDROP", implode("\n", array_map(function($param) { return "CacheKeyModify -qs:$param"; }, array_filter($nitro->getConfig()->IgnoredParams, function($param) { return $param != "ignorenitro"; }))), $rules);
173
  }
constants.php CHANGED
@@ -6,7 +6,7 @@ function nitropack_trailingslashit($string) {
6
  return rtrim( $string, '/\\' ) . '/';
7
  }
8
 
9
- define( 'NITROPACK_VERSION', '1.5.15' );
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.16' );
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
@@ -1241,6 +1241,11 @@ function nitropack_sdk_invalidate($url = NULL, $tag = NULL, $reason = NULL) {
1241
  $nitro->invalidateCache($url, $tag, $reason);
1242
 
1243
  try {
 
 
 
 
 
1244
  do_action('nitropack_integration_purge_url', $homeUrl);
1245
 
1246
  if ($tag) {
@@ -1433,6 +1438,10 @@ function nitropack_sdk_purge($url = NULL, $tag = NULL, $reason = NULL, $type = \
1433
 
1434
  $nitro->purgeCache($url, $tag, $type, $reason);
1435
 
 
 
 
 
1436
  try {
1437
  do_action('nitropack_integration_purge_url', $homeUrl);
1438
 
1241
  $nitro->invalidateCache($url, $tag, $reason);
1242
 
1243
  try {
1244
+
1245
+ if (defined('NITROPACK_DEBUG_MODE')) {
1246
+ do_action('nitropack_debug_invalidate', $url, $tag, $reason);
1247
+ }
1248
+
1249
  do_action('nitropack_integration_purge_url', $homeUrl);
1250
 
1251
  if ($tag) {
1438
 
1439
  $nitro->purgeCache($url, $tag, $type, $reason);
1440
 
1441
+ if (defined('NITROPACK_DEBUG_MODE')) {
1442
+ do_action('nitropack_debug_purge', $url, $tag, $reason);
1443
+ }
1444
+
1445
  try {
1446
  do_action('nitropack_integration_purge_url', $homeUrl);
1447
 
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.15
7
  Author: NitroPack LLC
8
  Author URI: https://nitropack.io/
9
  License: GPL2
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.16
7
  Author: NitroPack LLC
8
  Author URI: https://nitropack.io/
9
  License: GPL2
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: nitropack
3
  Tags: cache,perfomance,optimize,pagespeed,lazy load,cdn,critical css,compression,defer css javascript,minify css,minify,webp
4
  Requires at least: 4.7
5
- Tested up to: 6.0.1
6
  Requires PHP: 5.6
7
- Stable tag: 1.5.15
8
  License: GNU General Public License, version 2
9
  License URI: https://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -169,6 +169,10 @@ No. We’ve designed NitroPack to be a very lightweight solution that adds no CP
169
 
170
  == Changelog ==
171
 
 
 
 
 
172
  = 1.5.15 =
173
  * Improvement: Better handling of healthchecks after LiteSpeed .htaccess configuration
174
  * Bug fix: Resolve an issue with sitemap XSL schemas
2
  Contributors: nitropack
3
  Tags: cache,perfomance,optimize,pagespeed,lazy load,cdn,critical css,compression,defer css javascript,minify css,minify,webp
4
  Requires at least: 4.7
5
+ Tested up to: 6.0.2
6
  Requires PHP: 5.6
7
+ Stable tag: 1.5.16
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.16 =
173
+ * Improvement: Update the compatibility with SiteGround's Dynamic Cache layer
174
+ * Bug fix: Resolve cache bypass issues on LiteSpeed
175
+
176
  = 1.5.15 =
177
  * Improvement: Better handling of healthchecks after LiteSpeed .htaccess configuration
178
  * Bug fix: Resolve an issue with sitemap XSL schemas