Version Description
- New Feature: Safe Mode toggle within the plugin's dashboard
- Improvement: Add support for an upcoming improvement in the compatibility with reverse proxies like Cloudflare and Sucuri
- Improvement: Add a filter to allow the list of cacheable post types to be extended -
nitropack_cacheable_post_types
- Improvement: Better handling of WooCommerce price updates
- Bug fix: Cache warmup was not being triggerd when posting a new article. This is resolved now.
Download this release
Release Info
Developer | nitropack |
Plugin | NitroPack |
Version | 1.5.3 |
Comparing to | |
See all releases |
Code changes from version 1.5.2 to 1.5.3
- constants.php +2 -2
- functions.php +116 -7
- main.php +6 -1
- nitropack-sdk/NitroPack/SDK/Api.php +6 -0
- nitropack-sdk/NitroPack/SDK/Api/Cache.php +4 -0
- nitropack-sdk/NitroPack/SDK/Api/SafeMode.php +46 -0
- nitropack-sdk/NitroPack/SDK/Backlog.php +3 -0
- nitropack-sdk/NitroPack/SDK/NitroPack.php +11 -0
- readme.txt +8 -1
- view/connect.php +1 -1
- view/dashboard.php +83 -3
- view/images/nitropackwp.jpg +0 -0
- view/stylesheet/admin_bar_menu.css +2 -0
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' );
|
@@ -21,4 +21,4 @@ if (!defined("NITROPACK_REDIS_PASS")) define("NITROPACK_REDIS_PASS", NULL); // S
|
|
21 |
if (!defined("NITROPACK_REDIS_DB")) define("NITROPACK_REDIS_DB", NULL); // Set this to the number of the Redis DB if you'd like to not use the default one
|
22 |
|
23 |
if (!defined("NITROPACK_SUPPORT_BUBBLE_VISIBLE")) define("NITROPACK_SUPPORT_BUBBLE_VISIBLE", true);
|
24 |
-
if (!defined("NITROPACK_SUPPORT_BUBBLE_URL")) define("NITROPACK_SUPPORT_BUBBLE_URL", "https://
|
6 |
return rtrim( $string, '/\\' ) . '/';
|
7 |
}
|
8 |
|
9 |
+
define( 'NITROPACK_VERSION', '1.5.3' );
|
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' );
|
21 |
if (!defined("NITROPACK_REDIS_DB")) define("NITROPACK_REDIS_DB", NULL); // Set this to the number of the Redis DB if you'd like to not use the default one
|
22 |
|
23 |
if (!defined("NITROPACK_SUPPORT_BUBBLE_VISIBLE")) define("NITROPACK_SUPPORT_BUBBLE_VISIBLE", true);
|
24 |
+
if (!defined("NITROPACK_SUPPORT_BUBBLE_URL")) define("NITROPACK_SUPPORT_BUBBLE_URL", "https://support.nitropack.io/");
|
functions.php
CHANGED
@@ -13,6 +13,7 @@ $np_preUpdatePosts = array();
|
|
13 |
$np_preUpdateTaxonomies = array();
|
14 |
$np_loggedPurges = array();
|
15 |
$np_loggedInvalidations = array();
|
|
|
16 |
$np_sdkObjects = array();
|
17 |
$np_ignoreUpdatePostIDs = array();
|
18 |
$np_integrationSetupEvent = "muplugins_loaded";
|
@@ -485,6 +486,11 @@ function nitropack_init() {
|
|
485 |
add_action('get_footer', 'nitropack_print_beacon_script');
|
486 |
}
|
487 |
}
|
|
|
|
|
|
|
|
|
|
|
488 |
}
|
489 |
}
|
490 |
}
|
@@ -594,6 +600,26 @@ function nitropack_get_beacon_script() {
|
|
594 |
}
|
595 |
}
|
596 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
function nitropack_has_advanced_cache() {
|
598 |
return defined( 'NITROPACK_ADVANCED_CACHE' );
|
599 |
}
|
@@ -654,7 +680,7 @@ function nitropack_get_object_types() {
|
|
654 |
}
|
655 |
|
656 |
function nitropack_get_cacheable_object_types() {
|
657 |
-
return get_option("nitropack-cacheableObjectTypes", nitropack_get_default_cacheable_object_types());
|
658 |
}
|
659 |
|
660 |
/** Step 3. */
|
@@ -1327,6 +1353,20 @@ function nitropack_execute_invalidations() {
|
|
1327 |
}
|
1328 |
}
|
1329 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1330 |
function nitropack_fetch_config() {
|
1331 |
if (null !== $nitro = get_nitropack_sdk()) {
|
1332 |
try {
|
@@ -1566,7 +1606,7 @@ function nitropack_handle_comment_post($commentID, $isApproved) {
|
|
1566 |
}
|
1567 |
|
1568 |
function nitropack_handle_post_transition($new, $old, $post) {
|
1569 |
-
global $np_ignoreUpdatePostIDs;
|
1570 |
if (!empty($post->ID) && in_array($post->ID, $np_ignoreUpdatePostIDs)) return;
|
1571 |
if (!get_option("nitropack-autoCachePurge", 1)) return;
|
1572 |
|
@@ -1607,17 +1647,14 @@ function nitropack_handle_post_transition($new, $old, $post) {
|
|
1607 |
nitropack_clean_post_cache($post, array('added' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to scheduling %s '%s'", $nicePostTypeLabel, $post->post_title));
|
1608 |
} else if ($new == "publish" && $old != "publish") {
|
1609 |
nitropack_clean_post_cache($post, array('added' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to publishing %s '%s'", $nicePostTypeLabel, $post->post_title));
|
1610 |
-
|
1611 |
-
try {
|
1612 |
-
$nitro->getApi()->runWarmup(get_permalink($post));
|
1613 |
-
} catch (\Exception $e) {}
|
1614 |
-
}
|
1615 |
} else if ($new == "trash" && $old == "publish") {
|
1616 |
nitropack_clean_post_cache($post, array('deleted' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to deleting %s '%s'", $nicePostTypeLabel, $post->post_title), true);
|
1617 |
} else if ($new == "private" && $old == "publish") {
|
1618 |
nitropack_clean_post_cache($post, array('deleted' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to making %s '%s' private", $nicePostTypeLabel, $post->post_title), true);
|
1619 |
} else if ($new != "trash") {
|
1620 |
nitropack_clean_post_cache($post);
|
|
|
1621 |
}
|
1622 |
break;
|
1623 |
}
|
@@ -1637,6 +1674,17 @@ function nitropack_handle_product_stock_updates($product_id) {
|
|
1637 |
}
|
1638 |
}
|
1639 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1640 |
function nitropack_handle_the_post($post) {
|
1641 |
global $np_customExpirationTimes, $np_queriedObj;
|
1642 |
if (defined('POSTEXPIRATOR_VERSION')) {
|
@@ -2087,6 +2135,67 @@ function nitropack_warmup_stats() {
|
|
2087 |
));
|
2088 |
}
|
2089 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2090 |
function nitropack_data_dir_exists() {
|
2091 |
return defined("NITROPACK_DATA_DIR") && is_dir(NITROPACK_DATA_DIR);
|
2092 |
}
|
13 |
$np_preUpdateTaxonomies = array();
|
14 |
$np_loggedPurges = array();
|
15 |
$np_loggedInvalidations = array();
|
16 |
+
$np_loggedWarmups = array();
|
17 |
$np_sdkObjects = array();
|
18 |
$np_ignoreUpdatePostIDs = array();
|
19 |
$np_integrationSetupEvent = "muplugins_loaded";
|
486 |
add_action('get_footer', 'nitropack_print_beacon_script');
|
487 |
}
|
488 |
}
|
489 |
+
|
490 |
+
if (!nitropack_is_optimizer_request() && nitropack_passes_page_requirements()) {// This is a cacheable URL
|
491 |
+
add_action('wp_footer', 'nitropack_print_telemetry_script');
|
492 |
+
add_action('get_footer', 'nitropack_print_telemetry_script');
|
493 |
+
}
|
494 |
}
|
495 |
}
|
496 |
}
|
600 |
}
|
601 |
}
|
602 |
|
603 |
+
function nitropack_print_telemetry_script() {
|
604 |
+
if (defined("NITROPACK_TELEMETRY_PRINTED")) return;
|
605 |
+
define("NITROPACK_TELEMTRY_PRINTED", true);
|
606 |
+
echo nitropack_get_telemetry_script();
|
607 |
+
}
|
608 |
+
|
609 |
+
function nitropack_get_telemetry_script() {
|
610 |
+
$siteConfig = nitropack_get_site_config();
|
611 |
+
if ($siteConfig && !empty($siteConfig["siteId"]) && !empty($siteConfig["siteSecret"])) {
|
612 |
+
if (null !== $nitro = get_nitropack_sdk($siteConfig["siteId"], $siteConfig["siteSecret"]) ) {
|
613 |
+
$config = $nitro->getConfig();
|
614 |
+
if (!empty($config->Telemetry)) {
|
615 |
+
return "<script id='nitro-telemetry'>" . $config->Telemetry . "</script>";
|
616 |
+
}
|
617 |
+
}
|
618 |
+
}
|
619 |
+
|
620 |
+
return "";
|
621 |
+
}
|
622 |
+
|
623 |
function nitropack_has_advanced_cache() {
|
624 |
return defined( 'NITROPACK_ADVANCED_CACHE' );
|
625 |
}
|
680 |
}
|
681 |
|
682 |
function nitropack_get_cacheable_object_types() {
|
683 |
+
return apply_filters("nitropack_cacheable_post_types", get_option("nitropack-cacheableObjectTypes", nitropack_get_default_cacheable_object_types()));
|
684 |
}
|
685 |
|
686 |
/** Step 3. */
|
1353 |
}
|
1354 |
}
|
1355 |
|
1356 |
+
function nitropack_execute_warmups() {
|
1357 |
+
global $np_loggedWarmups;
|
1358 |
+
try {
|
1359 |
+
if (!empty($np_loggedWarmups) && (null !== $nitro = get_nitropack_sdk())) {
|
1360 |
+
$warmupStats = $nitro->getApi()->getWarmupStats();
|
1361 |
+
if (!empty($warmupStats["status"])) {
|
1362 |
+
foreach (array_unique($np_loggedWarmups) as $url) {
|
1363 |
+
$nitro->getApi()->runWarmup($url);
|
1364 |
+
}
|
1365 |
+
}
|
1366 |
+
}
|
1367 |
+
} catch (\Exception $e) {}
|
1368 |
+
}
|
1369 |
+
|
1370 |
function nitropack_fetch_config() {
|
1371 |
if (null !== $nitro = get_nitropack_sdk()) {
|
1372 |
try {
|
1606 |
}
|
1607 |
|
1608 |
function nitropack_handle_post_transition($new, $old, $post) {
|
1609 |
+
global $np_ignoreUpdatePostIDs, $np_loggedWarmups;
|
1610 |
if (!empty($post->ID) && in_array($post->ID, $np_ignoreUpdatePostIDs)) return;
|
1611 |
if (!get_option("nitropack-autoCachePurge", 1)) return;
|
1612 |
|
1647 |
nitropack_clean_post_cache($post, array('added' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to scheduling %s '%s'", $nicePostTypeLabel, $post->post_title));
|
1648 |
} else if ($new == "publish" && $old != "publish") {
|
1649 |
nitropack_clean_post_cache($post, array('added' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to publishing %s '%s'", $nicePostTypeLabel, $post->post_title));
|
1650 |
+
$np_loggedWarmups[] = get_permalink($post);
|
|
|
|
|
|
|
|
|
1651 |
} else if ($new == "trash" && $old == "publish") {
|
1652 |
nitropack_clean_post_cache($post, array('deleted' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to deleting %s '%s'", $nicePostTypeLabel, $post->post_title), true);
|
1653 |
} else if ($new == "private" && $old == "publish") {
|
1654 |
nitropack_clean_post_cache($post, array('deleted' => nitropack_get_taxonomies($post)), true, sprintf("Invalidate related pages due to making %s '%s' private", $nicePostTypeLabel, $post->post_title), true);
|
1655 |
} else if ($new != "trash") {
|
1656 |
nitropack_clean_post_cache($post);
|
1657 |
+
$np_loggedWarmups[] = get_permalink($post);
|
1658 |
}
|
1659 |
break;
|
1660 |
}
|
1674 |
}
|
1675 |
}
|
1676 |
|
1677 |
+
function nitropack_handle_product_price_updates($product_id) {
|
1678 |
+
if (!get_option("nitropack-autoCachePurge", 1)) return;
|
1679 |
+
|
1680 |
+
try {
|
1681 |
+
$post = get_post($product_id);
|
1682 |
+
nitropack_clean_post_cache($post, NULL, true, sprintf("Invalidate product '%s' due to price change", $post->post_title)); // Update the product page and all related pages, because the price change might have to be reflected on category pages
|
1683 |
+
} catch (\Exception $e) {
|
1684 |
+
// TODO: Log the error
|
1685 |
+
}
|
1686 |
+
}
|
1687 |
+
|
1688 |
function nitropack_handle_the_post($post) {
|
1689 |
global $np_customExpirationTimes, $np_queriedObj;
|
1690 |
if (defined('POSTEXPIRATOR_VERSION')) {
|
2135 |
));
|
2136 |
}
|
2137 |
|
2138 |
+
function nitropack_enable_safemode() {
|
2139 |
+
if (null !== $nitro = get_nitropack_sdk()) {
|
2140 |
+
try {
|
2141 |
+
$nitro->enableSafeMode();
|
2142 |
+
} catch (\Exception $e) {
|
2143 |
+
}
|
2144 |
+
|
2145 |
+
nitropack_json_and_exit(array(
|
2146 |
+
"type" => "success",
|
2147 |
+
"message" => "Success! Safe mode has been enabled successfully!"
|
2148 |
+
));
|
2149 |
+
}
|
2150 |
+
|
2151 |
+
nitropack_json_and_exit(array(
|
2152 |
+
"type" => "error",
|
2153 |
+
"message" => "Error! There was an error while enabling safe mode!"
|
2154 |
+
));
|
2155 |
+
}
|
2156 |
+
|
2157 |
+
function nitropack_disable_safemode() {
|
2158 |
+
if (null !== $nitro = get_nitropack_sdk()) {
|
2159 |
+
try {
|
2160 |
+
$nitro->disableSafeMode();
|
2161 |
+
} catch (\Exception $e) {
|
2162 |
+
}
|
2163 |
+
|
2164 |
+
nitropack_json_and_exit(array(
|
2165 |
+
"type" => "success",
|
2166 |
+
"message" => "Success! Safe mode has been disabled successfully!"
|
2167 |
+
));
|
2168 |
+
}
|
2169 |
+
|
2170 |
+
nitropack_json_and_exit(array(
|
2171 |
+
"type" => "error",
|
2172 |
+
"message" => "Error! There was an error while disabling safe mode!"
|
2173 |
+
));
|
2174 |
+
}
|
2175 |
+
|
2176 |
+
function nitropack_safemode_status() {
|
2177 |
+
if (null !== $nitro = get_nitropack_sdk()) {
|
2178 |
+
try {
|
2179 |
+
$isEnabled = $nitro->getApi()->isSafeModeEnabled();
|
2180 |
+
} catch (\Exception $e) {
|
2181 |
+
nitropack_json_and_exit(array(
|
2182 |
+
"type" => "error",
|
2183 |
+
"message" => "Error! There was an error while fetching the status of safe mode!"
|
2184 |
+
));
|
2185 |
+
}
|
2186 |
+
|
2187 |
+
nitropack_json_and_exit(array(
|
2188 |
+
"type" => "success",
|
2189 |
+
"isEnabled" => $isEnabled
|
2190 |
+
));
|
2191 |
+
}
|
2192 |
+
|
2193 |
+
nitropack_json_and_exit(array(
|
2194 |
+
"type" => "error",
|
2195 |
+
"message" => "Error! There was an error while fetching status of safe mode!"
|
2196 |
+
));
|
2197 |
+
}
|
2198 |
+
|
2199 |
function nitropack_data_dir_exists() {
|
2200 |
return defined("NITROPACK_DATA_DIR") && is_dir(NITROPACK_DATA_DIR);
|
2201 |
}
|
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
|
@@ -41,8 +41,10 @@ add_action( 'comment_post', 'nitropack_handle_comment_post', 10, 2);
|
|
41 |
add_action( 'switch_theme', 'nitropack_switch_theme' );
|
42 |
add_action( 'shutdown', 'nitropack_execute_purges', -1000 );
|
43 |
add_action( 'shutdown', 'nitropack_execute_invalidations', -1000 );
|
|
|
44 |
|
45 |
add_action( 'woocommerce_updated_product_stock', 'nitropack_handle_product_stock_updates', 0, 1);
|
|
|
46 |
add_action( 'woocommerce_rest_insert_product', function($post, $request, $creating) {
|
47 |
if (!$creating) {
|
48 |
nitropack_clean_post_cache($post);
|
@@ -93,6 +95,9 @@ if ( is_admin() ) {
|
|
93 |
add_action( 'wp_ajax_nitropack_dismiss_hosting_notice', 'nitropack_dismiss_hosting_notice' );
|
94 |
add_action( 'wp_ajax_nitropack_reconfigure_webhooks', 'nitropack_reconfigure_webhooks' );
|
95 |
add_action( 'wp_ajax_nitropack_generate_report', 'nitropack_generate_report' );//diag_ajax_hook
|
|
|
|
|
|
|
96 |
add_action( 'update_option_nitropack-enableCompression', 'nitropack_handle_compression_toggle', 10, 2 );
|
97 |
add_action( 'add_meta_boxes', 'nitropack_add_meta_box' );
|
98 |
|
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.3
|
7 |
Author: NitroPack LLC
|
8 |
Author URI: https://nitropack.io/
|
9 |
License: GPL2
|
41 |
add_action( 'switch_theme', 'nitropack_switch_theme' );
|
42 |
add_action( 'shutdown', 'nitropack_execute_purges', -1000 );
|
43 |
add_action( 'shutdown', 'nitropack_execute_invalidations', -1000 );
|
44 |
+
add_action( 'shutdown', 'nitropack_execute_warmups', -1000 );
|
45 |
|
46 |
add_action( 'woocommerce_updated_product_stock', 'nitropack_handle_product_stock_updates', 0, 1);
|
47 |
+
add_action( 'woocommerce_updated_product_price', 'nitropack_handle_product_price_updates', 0, 1);
|
48 |
add_action( 'woocommerce_rest_insert_product', function($post, $request, $creating) {
|
49 |
if (!$creating) {
|
50 |
nitropack_clean_post_cache($post);
|
95 |
add_action( 'wp_ajax_nitropack_dismiss_hosting_notice', 'nitropack_dismiss_hosting_notice' );
|
96 |
add_action( 'wp_ajax_nitropack_reconfigure_webhooks', 'nitropack_reconfigure_webhooks' );
|
97 |
add_action( 'wp_ajax_nitropack_generate_report', 'nitropack_generate_report' );//diag_ajax_hook
|
98 |
+
add_action( 'wp_ajax_nitropack_enable_safemode', 'nitropack_enable_safemode' );
|
99 |
+
add_action( 'wp_ajax_nitropack_disable_safemode', 'nitropack_disable_safemode' );
|
100 |
+
add_action( 'wp_ajax_nitropack_safemode_status', 'nitropack_safemode_status' );
|
101 |
add_action( 'update_option_nitropack-enableCompression', 'nitropack_handle_compression_toggle', 10, 2 );
|
102 |
add_action( 'add_meta_boxes', 'nitropack_add_meta_box' );
|
103 |
|
nitropack-sdk/NitroPack/SDK/Api.php
CHANGED
@@ -20,6 +20,7 @@ class Api {
|
|
20 |
$this->children["warmup"] = new Api\Warmup($siteId, $siteSecret);
|
21 |
$this->children["integration"] = new Api\Integration($siteId, $siteSecret);
|
22 |
$this->children["variation_cookie"] = new Api\VariationCookie($siteId, $siteSecret);
|
|
|
23 |
$this->children["request_maker"] = new Api\RequestMaker($siteId);
|
24 |
$this->children["secure_request_maker"] = new Api\SecureRequestMaker($siteId, $siteSecret);
|
25 |
|
@@ -271,4 +272,9 @@ class Api {
|
|
271 |
public function getWebsitesPaginated($page, $limit = 250) {
|
272 |
return $this->integration->readPaginated($page, $limit);
|
273 |
}
|
|
|
|
|
|
|
|
|
|
|
274 |
}
|
20 |
$this->children["warmup"] = new Api\Warmup($siteId, $siteSecret);
|
21 |
$this->children["integration"] = new Api\Integration($siteId, $siteSecret);
|
22 |
$this->children["variation_cookie"] = new Api\VariationCookie($siteId, $siteSecret);
|
23 |
+
$this->children["safe_mode"] = new Api\SafeMode($siteId, $siteSecret);
|
24 |
$this->children["request_maker"] = new Api\RequestMaker($siteId);
|
25 |
$this->children["secure_request_maker"] = new Api\SecureRequestMaker($siteId, $siteSecret);
|
26 |
|
272 |
public function getWebsitesPaginated($page, $limit = 250) {
|
273 |
return $this->integration->readPaginated($page, $limit);
|
274 |
}
|
275 |
+
|
276 |
+
public function isSafeModeEnabled() {
|
277 |
+
$status = $this->safe_mode->status();
|
278 |
+
return !empty($status->isEnabled);
|
279 |
+
}
|
280 |
}
|
nitropack-sdk/NitroPack/SDK/Api/Cache.php
CHANGED
@@ -35,6 +35,10 @@ class Cache extends SignedBase {
|
|
35 |
$headers['X-Nitro-Priority'] = 'LOW';
|
36 |
}
|
37 |
|
|
|
|
|
|
|
|
|
38 |
$httpResponse = $this->makeRequest($path, $headers, $cookies);
|
39 |
$status = ResponseStatus::getStatus($httpResponse->getStatusCode());
|
40 |
$body = $httpResponse->getBody();
|
35 |
$headers['X-Nitro-Priority'] = 'LOW';
|
36 |
}
|
37 |
|
38 |
+
if (!empty($this->nitropack->getConfig()->LoopbackRequests)) {
|
39 |
+
$headers['X-Nitro-Loopback'] = '1';
|
40 |
+
}
|
41 |
+
|
42 |
$httpResponse = $this->makeRequest($path, $headers, $cookies);
|
43 |
$status = ResponseStatus::getStatus($httpResponse->getStatusCode());
|
44 |
$body = $httpResponse->getBody();
|
nitropack-sdk/NitroPack/SDK/Api/SafeMode.php
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
namespace NitroPack\SDK\Api;
|
3 |
+
|
4 |
+
class SafeMode extends Base {
|
5 |
+
public function status() {
|
6 |
+
$path = 'safemode/status/' . $this->siteId;
|
7 |
+
|
8 |
+
$httpResponse = $this->makeRequest($path);
|
9 |
+
|
10 |
+
$status = ResponseStatus::getStatus($httpResponse->getStatusCode());
|
11 |
+
switch ($status) {
|
12 |
+
case ResponseStatus::OK:
|
13 |
+
return json_decode($httpResponse->getBody());
|
14 |
+
default:
|
15 |
+
$this->throwException($httpResponse, 'Error while enabling safe mode: %s');
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
public function enable() {
|
20 |
+
$path = 'safemode/enable/' . $this->siteId;
|
21 |
+
|
22 |
+
$httpResponse = $this->makeRequest($path, array(), array(), 'POST');
|
23 |
+
|
24 |
+
$status = ResponseStatus::getStatus($httpResponse->getStatusCode());
|
25 |
+
switch ($status) {
|
26 |
+
case ResponseStatus::OK:
|
27 |
+
return true;
|
28 |
+
default:
|
29 |
+
$this->throwException($httpResponse, 'Error while enabling safe mode: %s');
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
public function disable() {
|
34 |
+
$path = 'safemode/disable/' . $this->siteId;
|
35 |
+
|
36 |
+
$httpResponse = $this->makeRequest($path, array(), array(), 'POST');
|
37 |
+
|
38 |
+
$status = ResponseStatus::getStatus($httpResponse->getStatusCode());
|
39 |
+
switch ($status) {
|
40 |
+
case ResponseStatus::OK:
|
41 |
+
return true;
|
42 |
+
default:
|
43 |
+
$this->throwException($httpResponse, 'Error while disabling safe mode: %s');
|
44 |
+
}
|
45 |
+
}
|
46 |
+
}
|
nitropack-sdk/NitroPack/SDK/Backlog.php
CHANGED
@@ -35,6 +35,7 @@ class Backlog {
|
|
35 |
}
|
36 |
|
37 |
public function append($entry) {
|
|
|
38 |
$fh = $this->getHandle();
|
39 |
Filesystem::flock($fh, LOCK_EX);
|
40 |
Filesystem::fseek($fh, 0, SEEK_END);
|
@@ -43,6 +44,7 @@ class Backlog {
|
|
43 |
}
|
44 |
|
45 |
public function replay($timeLimit = 10) {
|
|
|
46 |
$fh = $this->getHandle();
|
47 |
Filesystem::flock($fh, LOCK_EX);
|
48 |
$lastProcessingTimestamp = $this->header->lastProcessingTimestamp;
|
@@ -104,6 +106,7 @@ class Backlog {
|
|
104 |
}
|
105 |
|
106 |
public function exists() {
|
|
|
107 |
return Filesystem::fileExists($this->queuePath);
|
108 |
}
|
109 |
|
35 |
}
|
36 |
|
37 |
public function append($entry) {
|
38 |
+
if (defined("NITROPACK_DISABLE_BACKLOG")) return;
|
39 |
$fh = $this->getHandle();
|
40 |
Filesystem::flock($fh, LOCK_EX);
|
41 |
Filesystem::fseek($fh, 0, SEEK_END);
|
44 |
}
|
45 |
|
46 |
public function replay($timeLimit = 10) {
|
47 |
+
if (defined("NITROPACK_DISABLE_BACKLOG")) return;
|
48 |
$fh = $this->getHandle();
|
49 |
Filesystem::flock($fh, LOCK_EX);
|
50 |
$lastProcessingTimestamp = $this->header->lastProcessingTimestamp;
|
106 |
}
|
107 |
|
108 |
public function exists() {
|
109 |
+
if (defined("NITROPACK_DISABLE_BACKLOG")) return false;
|
110 |
return Filesystem::fileExists($this->queuePath);
|
111 |
}
|
112 |
|
nitropack-sdk/NitroPack/SDK/NitroPack.php
CHANGED
@@ -221,6 +221,7 @@ class NitroPack {
|
|
221 |
}
|
222 |
|
223 |
public function loadHealthStatus() {
|
|
|
224 |
if (Filesystem::fileExists($this->getHealthStatusFile())) {
|
225 |
$this->healthStatus = Filesystem::fileGetContents($this->getHealthStatusFile());
|
226 |
} else {
|
@@ -695,6 +696,16 @@ class NitroPack {
|
|
695 |
return $embedjs->getUrl();
|
696 |
}
|
697 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
698 |
private function loadConfig() {
|
699 |
$file = $this->getConfigFile();
|
700 |
|
221 |
}
|
222 |
|
223 |
public function loadHealthStatus() {
|
224 |
+
if (defined("NITROPACK_DISABLE_BACKLOG")) return;
|
225 |
if (Filesystem::fileExists($this->getHealthStatusFile())) {
|
226 |
$this->healthStatus = Filesystem::fileGetContents($this->getHealthStatusFile());
|
227 |
} else {
|
696 |
return $embedjs->getUrl();
|
697 |
}
|
698 |
|
699 |
+
public function enableSafeMode() {
|
700 |
+
$this->api->safe_mode->enable();
|
701 |
+
$this->fetchConfig();
|
702 |
+
}
|
703 |
+
|
704 |
+
public function disableSafeMode() {
|
705 |
+
$this->api->safe_mode->disable();
|
706 |
+
$this->fetchConfig();
|
707 |
+
}
|
708 |
+
|
709 |
private function loadConfig() {
|
710 |
$file = $this->getConfigFile();
|
711 |
|
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.6
|
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,13 @@ No. We’ve designed NitroPack to be a very lightweight solution that adds no CP
|
|
169 |
|
170 |
== Changelog ==
|
171 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
= 1.5.2 =
|
173 |
* Improvement: Faster cache purge via the webhook
|
174 |
* Improvement: Purging/Invalidating cache via WP-CLI is now direct and provides better feedback of the result
|
4 |
Requires at least: 4.7
|
5 |
Tested up to: 5.6
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 1.5.3
|
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.3 =
|
173 |
+
* New Feature: Safe Mode toggle within the plugin's dashboard
|
174 |
+
* Improvement: Add support for an upcoming improvement in the compatibility with reverse proxies like Cloudflare and Sucuri
|
175 |
+
* Improvement: Add a filter to allow the list of cacheable post types to be extended - `nitropack_cacheable_post_types`
|
176 |
+
* Improvement: Better handling of WooCommerce price updates
|
177 |
+
* Bug fix: Cache warmup was not being triggerd when posting a new article. This is resolved now.
|
178 |
+
|
179 |
= 1.5.2 =
|
180 |
* Improvement: Faster cache purge via the webhook
|
181 |
* Improvement: Purging/Invalidating cache via WP-CLI is now direct and provides better feedback of the result
|
view/connect.php
CHANGED
@@ -29,7 +29,7 @@
|
|
29 |
<a onclick="jQuery('#manual-connect-fields').show(); jQuery(this).hide();" id="reveal-manual-connect"><small>Enter details manually</small></a>
|
30 |
</div>
|
31 |
</form>
|
32 |
-
<p>
|
33 |
</div>
|
34 |
</div>
|
35 |
</div>
|
29 |
<a onclick="jQuery('#manual-connect-fields').show(); jQuery(this).hide();" id="reveal-manual-connect"><small>Enter details manually</small></a>
|
30 |
</div>
|
31 |
</form>
|
32 |
+
<p>Having trouble connecting? Head over to <a href="https://support.nitropack.io/" target="_blank" rel="noreferrer noopener">https://support.nitropack.io/</a>.</p>
|
33 |
</div>
|
34 |
</div>
|
35 |
</div>
|
view/dashboard.php
CHANGED
@@ -97,7 +97,7 @@
|
|
97 |
<ul class="list-group list-group-flush">
|
98 |
<li class="list-group-item px-0 d-flex justify-content-between align-items-center">
|
99 |
<span>Cache Warmup</br>
|
100 |
-
<small>Learn more about this feature <a href="https://
|
101 |
</span>
|
102 |
<span id="loading-warmup-status">
|
103 |
Loading cache warmup status <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i>
|
@@ -109,6 +109,20 @@
|
|
109 |
</label>
|
110 |
</span>
|
111 |
</li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
<li class="list-group-item px-0 d-flex justify-content-between align-items-center">
|
113 |
<span id="detecting-compression" style="display: none;">Testing current compression status <a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span>
|
114 |
<span id="detected-compression">HTML Compression <a href="javascript:void(0);" id="compression-test-btn" data-toggle="tooltip" data-placement="top" title="Automatically detect whether compression is needed"><i class="fa fa-refresh" style="color: var(--blue);"></i></a></span>
|
@@ -353,6 +367,34 @@
|
|
353 |
});
|
354 |
}
|
355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
var getOptimizations = _ => {
|
357 |
$.ajax({
|
358 |
url: '<?php echo $optimizationDetailsUrl; ?>',
|
@@ -537,11 +579,16 @@
|
|
537 |
$("#settings-widget").cardOverlay("clear");
|
538 |
}
|
539 |
|
|
|
|
|
|
|
|
|
|
|
540 |
$(document).on('click', "#disconnect-btn", e => {
|
541 |
e.preventDefault();
|
542 |
|
543 |
-
var confirmHtml = '<p>
|
544 |
-
confirmHtml += '<p><a href="javascript:void(0);" onclick="rejectDisconnect()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="confirmDisconnect()" class="btn btn-
|
545 |
$("#settings-widget").cardOverlay("notify", {message: confirmHtml});
|
546 |
});
|
547 |
|
@@ -576,6 +623,39 @@
|
|
576 |
});
|
577 |
}
|
578 |
loadWarmupStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
579 |
})(jQuery);
|
580 |
|
581 |
(_ => {
|
97 |
<ul class="list-group list-group-flush">
|
98 |
<li class="list-group-item px-0 d-flex justify-content-between align-items-center">
|
99 |
<span>Cache Warmup</br>
|
100 |
+
<small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/1500002555901-Cache-Warmup-WordPress-" target="_blank" rel="noreferrer noopener">here</a></small>
|
101 |
</span>
|
102 |
<span id="loading-warmup-status">
|
103 |
Loading cache warmup status <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i>
|
109 |
</label>
|
110 |
</span>
|
111 |
</li>
|
112 |
+
<li class="list-group-item px-0 d-flex justify-content-between align-items-center">
|
113 |
+
<span>Safe Mode</br>
|
114 |
+
<small>Learn more about this feature <a href="https://support.nitropack.io/hc/en-us/articles/360060910574-Safe-Mode" target="_blank" rel="noreferrer noopener">here</a></small>
|
115 |
+
</span>
|
116 |
+
<span id="loading-safemode-status">
|
117 |
+
Loading safe mode status <i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i>
|
118 |
+
</span>
|
119 |
+
<span id="safemode-toggle" style="display: none;">
|
120 |
+
<label id="safemode-status-slider" class="switch">
|
121 |
+
<input type="checkbox" id="safemode-status">
|
122 |
+
<span class="slider"></span>
|
123 |
+
</label>
|
124 |
+
</span>
|
125 |
+
</li>
|
126 |
<li class="list-group-item px-0 d-flex justify-content-between align-items-center">
|
127 |
<span id="detecting-compression" style="display: none;">Testing current compression status <a href="javascript:void(0);"><i class="fa fa-refresh fa-spin" style="color: var(--blue);"></i></a></span>
|
128 |
<span id="detected-compression">HTML Compression <a href="javascript:void(0);" id="compression-test-btn" data-toggle="tooltip" data-placement="top" title="Automatically detect whether compression is needed"><i class="fa fa-refresh" style="color: var(--blue);"></i></a></span>
|
367 |
});
|
368 |
}
|
369 |
|
370 |
+
var enableSafemode = () => {
|
371 |
+
jQuery.post(ajaxurl, {
|
372 |
+
action: 'nitropack_enable_safemode'
|
373 |
+
}, function(response) {
|
374 |
+
var resp = JSON.parse(response);
|
375 |
+
if (resp.type == "success") {
|
376 |
+
$("#safemode-status").attr("checked", true);
|
377 |
+
// Success notification
|
378 |
+
} else {
|
379 |
+
$("#safemode-status").attr("checked", false);
|
380 |
+
// Error notification
|
381 |
+
}
|
382 |
+
});
|
383 |
+
}
|
384 |
+
|
385 |
+
var disableSafemode = () => {
|
386 |
+
jQuery.post(ajaxurl, {
|
387 |
+
action: 'nitropack_disable_safemode'
|
388 |
+
}, function(response) {
|
389 |
+
var resp = JSON.parse(response);
|
390 |
+
if (resp.type == "success") {
|
391 |
+
// Success notification
|
392 |
+
} else {
|
393 |
+
// Error notification
|
394 |
+
}
|
395 |
+
});
|
396 |
+
}
|
397 |
+
|
398 |
var getOptimizations = _ => {
|
399 |
$.ajax({
|
400 |
url: '<?php echo $optimizationDetailsUrl; ?>',
|
579 |
$("#settings-widget").cardOverlay("clear");
|
580 |
}
|
581 |
|
582 |
+
window.safemodeOnDisconnect = function() {
|
583 |
+
enableSafemode();
|
584 |
+
$("#settings-widget").cardOverlay("clear");
|
585 |
+
}
|
586 |
+
|
587 |
$(document).on('click', "#disconnect-btn", e => {
|
588 |
e.preventDefault();
|
589 |
|
590 |
+
var confirmHtml = '<p>Did you know that NitroPack offers a safe mode? We recommend using it instead of disconnecting. Are you sure that you wish to disconnect?</p>';
|
591 |
+
confirmHtml += '<p id="disconnectConfirmBtns"><a href="javascript:void(0);" onclick="rejectDisconnect()" class="btn btn-default btn-sm">No</a> <a href="javascript:void(0);" onclick="safemodeOnDisconnect()" class="btn btn-primary btn-sm">Enable Safe Mode</a> <a href="javascript:void(0);" onclick="confirmDisconnect()" class="btn btn-info btn-sm">Disconnect</a></p>';
|
592 |
$("#settings-widget").cardOverlay("notify", {message: confirmHtml});
|
593 |
});
|
594 |
|
623 |
});
|
624 |
}
|
625 |
loadWarmupStatus();
|
626 |
+
|
627 |
+
$("#safemode-status-slider").on("click", function(e) {
|
628 |
+
e.preventDefault();
|
629 |
+
var isEnabled = $("#safemode-status").is(":checked");
|
630 |
+
if (isEnabled) {
|
631 |
+
disableSafemode();
|
632 |
+
$("#safemode-status").attr("checked", false);
|
633 |
+
} else {
|
634 |
+
enableSafemode();
|
635 |
+
$("#safemode-status").attr("checked", true);
|
636 |
+
}
|
637 |
+
});
|
638 |
+
|
639 |
+
var loadSafemodeStatus = function() {
|
640 |
+
$.ajax({
|
641 |
+
url: ajaxurl,
|
642 |
+
type: "POST",
|
643 |
+
data: {
|
644 |
+
action: "nitropack_safemode_status"
|
645 |
+
},
|
646 |
+
dataType: "json",
|
647 |
+
success: function(resp) {
|
648 |
+
if (resp.type == "success") {
|
649 |
+
$("#safemode-status").attr("checked", !!resp.isEnabled);
|
650 |
+
$("#loading-safemode-status").hide();
|
651 |
+
$("#safemode-toggle").show();
|
652 |
+
} else {
|
653 |
+
setTimeout(loadSafemodeStatus, 500);
|
654 |
+
}
|
655 |
+
}
|
656 |
+
});
|
657 |
+
}
|
658 |
+
loadSafemodeStatus();
|
659 |
})(jQuery);
|
660 |
|
661 |
(_ => {
|
view/images/nitropackwp.jpg
CHANGED
Binary file
|
view/stylesheet/admin_bar_menu.css
CHANGED
@@ -20,6 +20,8 @@
|
|
20 |
}
|
21 |
|
22 |
.nitro-status {
|
|
|
|
|
23 |
font-size: 9px!important;
|
24 |
vertical-align: middle!important;
|
25 |
}
|
20 |
}
|
21 |
|
22 |
.nitro-status {
|
23 |
+
width: 9px!important;
|
24 |
+
height: 9px!important;
|
25 |
font-size: 9px!important;
|
26 |
vertical-align: middle!important;
|
27 |
}
|