PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.17.6
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.17.6
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 / view / dashboard.php
nitropack / view Last commit date
images 1 year ago javascript 1 year ago modals 1 year ago stylesheet 1 year ago templates 2 years ago admin.php 1 year ago connect-oneclick.php 1 year ago connect.php 2 years ago dashboard-oneclick.php 1 year ago dashboard.php 1 year ago oneclick.php 1 year ago safemode.php 2 years ago system-report.php 1 year ago
dashboard.php
591 lines
1 <?php
2 $settings = new \NitroPack\WordPress\Settings();
3 $usage = '0 MB';
4 $max_usage = '1 GB';
5 $page_views = '0';
6 $max_page_views = '10000'; ?>
7 <?php nitropack_display_admin_notices(); ?>
8 <div class="grid grid-cols-2 gap-6 grid-col-1-tablet items-start">
9 <div class="col-span-1">
10 <!-- Optimized Pages Card -->
11 <div class="card card-optimized-pages">
12 <div class="card-header">
13 <h3><?php esc_html_e('Optimized pages', 'nitropack'); ?></h3>
14 <div class="flex flex-row items-center" style="display: none;" id="pending-optimizations-section">
15 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="w-4 h-4">
16 <span class="ml-2 mr-1 text-primary"> <?php esc_html_e('Processing', 'nitropack'); ?>
17 <span id="pending-optimizations-count">X</span> <?php esc_html_e('page(s) in the background', 'nitropack'); ?></span>
18 </div>
19 </div>
20 <div class="card-body">
21 <div class="card-body-inner">
22 <div class="optimized-pages"><span data-optimized-pages-total>0</span></div>
23 <div class="text-box">
24 <div class="time-ago"><?php esc_html_e('Last cache purge', 'nitropack'); ?>: <span data-last-cache-purge><?php esc_html_e('Never', 'nitropack'); ?></span></div>
25 <div class="reason"><?php esc_html_e('Reason', 'nitropack'); ?>: <span data-purge-reason><?php esc_html_e('Unknown', 'nitropack'); ?></span></div>
26 </div>
27 <button id="optimizations-purge-cache" type="button" class="btn btn-secondary" data-modal-target="modal-purge-cache" data-modal-toggle="modal-purge-cache"><?php esc_html_e('Purge cache', 'nitropack'); ?></button>
28 </div>
29 </div>
30 <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-purge-cache.php'; ?>
31 </div>
32 <!-- Optimized Pages Card End -->
33 <!-- Optimization Mode Card -->
34 <div class="card card-optimization-mode">
35 <div class="card-header no-border mb-0">
36 <div class="flex items-center">
37 <h3 class="mb-0"><?php esc_html_e('Optimization mode', 'nitropack'); ?></h3>
38 <span class="tooltip-icon" data-tooltip-target="tooltip-optimization">
39 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/info.svg'; ?>">
40 </span>
41 <div id="tooltip-optimization" role="tooltip" class="tooltip-container hidden">
42 <?php esc_html_e('Select from our range of predefined optimization modes to boost your site\'s performance.', 'nitropack');
43 ?>
44 <div class="tooltip-arrow" data-popper-arrow></div>
45 </div>
46 </div>
47 </div>
48 <?php $modes = array('standard' => esc_html__('Standard', 'nitropack'), 'medium' => esc_html__('Medium', 'nitropack'), 'strong' => esc_html__('Strong', 'nitropack'), 'ludicrous' => esc_html__('Ludicrous', 'nitropack'), 'custom' => esc_html__('Custom', 'nitropack')); ?>
49 <div class="tabs-wrapper">
50 <div class="tabs" id="optimization-modes">
51 <?php foreach ($modes as $mode_id => $mode) : ?>
52 <a class="btn tab-link btn-link" data-mode="<?php echo $mode_id; ?>" data-modal-target="modal-optimization-mode" data-modal-toggle="modal-optimization-mode"><?php echo $mode; ?></a>
53 <?php endforeach; ?>
54 </div>
55 <p><?php esc_html_e('Active Mode', 'nitropack'); ?>: <span class="active-mode"></span></p>
56 <div class="tab-content-wrapper">
57 <div class="hidden tab-content" role="tabpanel" data-tab="standard-tab">
58 <p class="text-secondary mt-2"> <?php esc_html_e('Standard optimization features enabled for your site. Ideal choice for maximum stability.', 'nitropack'); ?></p>
59 </div>
60 <div class="hidden tab-content" role="tabpanel" data-tab="medium-tab">
61 <p class="text-secondary mt-2"> <?php esc_html_e('Adds image lazy loading to standard optimizations. Uses built-in browser techniques for loading resources.', 'nitropack'); ?></p>
62 </div>
63 <div class="hidden tab-content" role="tabpanel" data-tab="strong-tab">
64 <p class="text-secondary mt-2"> <?php esc_html_e('Includes smart resource loading on top of Medium optimizations. Balances speed boost with stability.', 'nitropack'); ?></p>
65 </div>
66 <div class="hidden tab-content" role="tabpanel" data-tab="ludicrous-tab">
67 <p class="text-secondary mt-2"> <?php esc_html_e('Applies deferred JS and advanced resource loading for optimal performance and Core Web Vitals.', 'nitropack'); ?></p>
68 </div>
69 <div class="hidden tab-content" role="tabpanel" data-tab="custom-tab">
70 <p class="text-secondary mt-2"> <?php esc_html_e('Activated when manual setups are made. Ideal for advanced NitroPack optimizations.', 'nitropack'); ?></p>
71 </div>
72 </div>
73 </div>
74 <div class="card-footer">
75 <div class="flex flex-row">
76 <p class=""><?php esc_html_e('Which optimization mode to choose?', 'nitropack'); ?></p>
77 <a class="text-primary btn-link ml-auto see-modes" data-modal-target="modes-modal" data-modal-toggle="modes-modal"><?php esc_html_e('See modes comparison', 'nitropack'); ?></a>
78 <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-modes.php'; ?>
79 </div>
80 </div>
81 <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-optimization-mode.php'; ?>
82 </div>
83 <!-- Optimization Mode Card End -->
84 <!-- Automated Behavior Card -->
85 <div class="card card-automated-behavior">
86 <div class="card-header">
87 <h3><?php esc_html_e('Automated Behavior', 'nitropack'); ?></h3>
88 </div>
89 <div class="card-body">
90 <div class="options-container">
91 <div class="nitro-option" id="purge-cache-widget">
92 <div class="nitro-option-main">
93 <div class="text-box">
94 <h6><?php esc_html_e('Purge cache', 'nitropack'); ?></h6>
95 <p><?php esc_html_e('Purge affected cache when content is updated or published', 'nitropack'); ?></p>
96 </div>
97 <label class="inline-flex items-center cursor-pointer ml-auto">
98 <input type="checkbox" value="" class="sr-only peer" name="purge_cache" id="auto-purge-status" <?php if ($autoCachePurge) echo "checked"; ?>>
99 <div class="toggle"></div>
100 </label>
101 </div>
102 </div>
103 <div class="nitro-option" id="page-optimization-widget">
104 <div class="nitro-option-main">
105 <div class="text-box">
106 <h6><?php esc_html_e('Page optimization', 'nitropack'); ?></h6>
107 <p><?php esc_html_e('Select what post/page types get optimized', 'nitropack'); ?></p>
108 </div>
109 <a data-modal-target="modal-posttypes" data-modal-toggle="modal-posttypes" class="btn btn-secondary btn-icon">
110 <img src="<?php echo plugin_dir_url(__FILE__); ?>images/setting-icon.svg">
111 </a>
112 </div>
113 <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-posttypes.php'; ?>
114 </div>
115 </div>
116 </div>
117 </div>
118 <!-- Automated Behavior Card End -->
119 <!-- Go to app Card -->
120 <div class="card exclusion-card">
121 <div class="card-header">
122 <h3><?php esc_html_e('Exclusions', 'nitropack'); ?></h3>
123 </div>
124 <div class="card-body">
125 <div class="options-container">
126 <div class="nitro-option" id="ajax-shortcodes-widget">
127 <?php $settings->shortcodes->render(); ?>
128 </div>
129 </div>
130 </div>
131 </div>
132 <!-- Go to app card End -->
133
134
135 </div>
136 <div class="col-span-1">
137 <!-- Subscription Card -->
138 <div class="card card-subscription">
139 <div class="card-header">
140 <h3><?php esc_html_e('Subscription', 'nitropack'); ?></h3>
141 </div>
142 <div class="card-body">
143 <div class="flex flex-row items-center">
144 <div class="plan-name"><?php esc_html_e('Free', 'nitropack'); ?></div>
145 <a type="button" target="_blank" href="https://app.nitropack.io/account/billing" class="btn btn-secondary ml-auto" id="btn-manage-subscription"><?php esc_html_e('Manage subscription', 'nitropack'); ?></a>
146 </div>
147 <div class="table-wrapper">
148 <table class="w-full">
149 <tbody>
150 <tr>
151 <td class="key"><?php esc_html_e('Next reset', 'nitropack'); ?></td>
152 <td class="value" data-next-reset><?php esc_html_e('No ETA', 'nitropack'); ?></td>
153 </tr>
154 <tr>
155 <td class="key"><?php esc_html_e('Next billing', 'nitropack'); ?></td>
156 <td class="value" data-next-billing><?php esc_html_e('No ETA', 'nitropack'); ?></td>
157 </tr>
158 <tr>
159 <td class="key"><?php esc_html_e('Page views', 'nitropack'); ?></td>
160 <td class="value" data-page-views><?php printf(esc_html__('%1$s out of %2$s', 'nitropack'), $page_views, $max_page_views); ?></td>
161 </tr>
162 <tr>
163 <td class="key"><?php esc_html_e('CDN bandwidth', 'nitropack'); ?></td>
164 <td class="value" data-cdn-bandwidth><?php printf(esc_html__('%1$s out of %2$s', 'nitropack'), $usage, $max_usage); ?></td>
165 </tr>
166 </tbody>
167 </table>
168 </div>
169 </div>
170 <div class="card-footer">
171 <p class="text-secondary text-smaller"><?php esc_html_e('You will be notified by email when your website reaches the subscription resource limits.', 'nitropack'); ?></p>
172 </div>
173 </div>
174 <!-- Subscription Card End -->
175 <!-- Basic Settings Card -->
176 <div class="card card-basic-settings">
177 <div class="card-header">
178 <h3><?php esc_html_e('Basic Settings', 'nitropack'); ?></h3>
179 </div>
180 <div class="card-body">
181 <div class="options-container">
182 <div class="nitro-option" id="cache-warmup-widget">
183 <div class="nitro-option-main">
184 <div class="text-box" id="warmup-status-slider">
185
186 <?php $sitemap = get_option('np_warmup_sitemap', false);
187 $toolTipDisplayState = $sitemap ? '' : 'hidden'; ?>
188
189 <h6><?php esc_html_e('Cache warmup', 'nitropack'); ?> <span class="badge badge-primary ml-2"><?php esc_html_e('Recommended', 'nitropack'); ?></span> <span class="tooltip-icon <?php echo $toolTipDisplayState; ?>" data-tooltip-target="tooltip-sitemap">
190 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/info.svg'; ?>">
191 </span></h6>
192 <div id="tooltip-sitemap" role="tooltip" class="tooltip-container hidden">
193 <?php echo $sitemap; ?>
194 <div class="tooltip-arrow" data-popper-arrow></div>
195 </div>
196 <p><?php esc_html_e('Automatically pre-caches your website\'s page content', 'nitropack'); ?>. <a href="https://support.nitropack.io/en/articles/8390320-cache-warmup" class="text-blue" target="_blank"><?php esc_html_e('Learn more', 'nitropack'); ?></a></p>
197 </div>
198 <label class="inline-flex items-center cursor-pointer ml-auto">
199 <input id="warmup-status" type="checkbox" class="sr-only peer">
200 <div class="toggle"></div>
201 </label>
202 </div>
203 <div class="msg-container" id="loading-warmup-status">
204 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="icon"> <span class="msg"><?php esc_html_e('Loading cache warmup status', 'nitropack'); ?></span>
205 </div>
206 </div>
207 <div class="nitro-option" id="test-mode-widget">
208 <div class="nitro-option-main">
209 <div class="text-box" id="safemode-status-slider">
210 <h6><?php esc_html_e('Test Mode', 'nitropack'); ?></h6>
211 <p><?php esc_html_e('Test NitroPack\'s features without affecting your visitors\' experience', 'nitropack'); ?>. <a href="https://support.nitropack.io/en/articles/8390292-test-mode" class="text-blue" target="_blank"><?php esc_html_e('Learn more', 'nitropack'); ?></a></p>
212 </div>
213
214 <label class="inline-flex items-center cursor-pointer ml-auto">
215 <input type="checkbox" class="sr-only peer" id="safemode-status">
216
217 <div class="toggle"></div>
218 </label>
219 </div>
220 <div class="msg-container" id="loading-safemode-status">
221 <img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="icon"> <?php esc_html_e('Loading test mode status', 'nitropack'); ?>
222 </div>
223 <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-test-mode.php'; ?>
224 </div>
225 <div class="nitro-option" id="compression-widget">
226 <div class="nitro-option-main">
227 <div class="text-box">
228 <h6><span id="detected-compression"><?php esc_html_e('HTML Compression', 'nitropack'); ?> </span></h6>
229 <p><?php esc_html_e('Compressing the structure of your HTML, ensures faster page rendering and an optimized browsing experience for your users.', 'nitropack'); ?> <a href="https://support.nitropack.io/en/articles/8390333-nitropack-plugin-settings-in-wordpress#h_29b7ab4836" class="text-blue" target="_blank"><?php esc_html_e('Learn more', 'nitropack'); ?></a></p>
230 </div>
231 <label class="inline-flex items-center cursor-pointer ml-auto">
232 <input type="checkbox" id="compression-status" class="sr-only peer" <?php echo (int)$enableCompression === 1 ? "checked" : ""; ?>>
233 <div class="toggle"></div>
234 </label>
235 </div>
236 <div class="mt-4 text-primary">
237 <a href="javascript:void(0);" id="compression-test-btn" class="text-primary"><?php esc_html_e('Run compression test', 'nitropack'); ?></a>
238 <div class="flex items-start msg-container hidden">
239 <span class="msg"></span>
240 </div>
241 </div>
242 </div>
243 <?php if (\NitroPack\Integration\Plugin\BeaverBuilder::isActive()) { ?>
244 <div class="nitro-option" id="beaver-builder-widget">
245 <div class="nitro-option-main">
246 <div class="text-box">
247 <h6><span id="detected-compression"><?php esc_html_e('Sync NitroPack Purge with Beaver Builder', 'nitropack'); ?> </span></h6>
248 <p><?php esc_html_e('When Beaver Builder cache is purged, NitroPack will perform a full cache purge keeping your site\'s content up-to-date.', 'nitropack'); ?></p>
249 </div>
250 <label class="inline-flex items-center cursor-pointer ml-auto">
251 <input type="checkbox" class="sr-only peer" id="bb-purge-status" <?php if ($bbCacheSyncPurge) echo "checked"; ?>>
252 <div class="toggle"></div>
253 </label>
254 </div>
255 </div>
256 <?php } ?>
257 <div class="nitro-option" id="can-editor-clear-cache-widget">
258 <div class="nitro-option-main">
259 <div class="text-box">
260 <h6><?php esc_html_e('Allow Editors to purge cache', 'nitropack'); ?> <span class="badge badge-success ml-2">New</span></h6>
261 <p><?php esc_html_e('Give Editors the right to purge cache when content is updated.', 'nitropack'); ?></p>
262 </div>
263 <label class="inline-flex items-center cursor-pointer ml-auto">
264 <input type="checkbox" id="can-editor-clear-cache" class="sr-only peer" <?php echo (int)$canEditorClearCache === 1 ? "checked" : ""; ?>>
265 <div class="toggle"></div>
266 </label>
267 </div>
268 </div>
269 <?php if (nitropack_render_woocommerce_cart_cache_option()) { ?>
270 <div class="nitro-option" id="cart-cache-widget">
271 <div class="nitro-option-main">
272 <div class="text-box">
273 <h6><?php esc_html_e('Cart cache', 'nitropack'); ?></h6>
274 <p><?php esc_html_e('Your visitors will enjoy full site speed while browsing with items in cart. Fully optimized page cache will be served.', 'nitropack'); ?></p>
275
276 </div>
277 <label class="inline-flex items-center cursor-pointer ml-auto">
278 <input type="checkbox" id="cart-cache-status" class="sr-only peer" <?php if (nitropack_is_cart_cache_active()) echo "checked"; ?> <?php if (!nitropack_is_cart_cache_available()) echo "disabled"; ?>>
279 <div class="toggle"></div>
280 </label>
281 </div>
282 <?php if (!nitropack_is_cart_cache_available()) : ?>
283 <div class="msg-container bg-success paid-msg">
284 <p><svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" class="text-success">
285 <g clip-path="url(#clip0_1244_36215)">
286 <path d="M10.0001 18.3333C14.6025 18.3333 18.3334 14.6023 18.3334 9.99996C18.3334 5.39759 14.6025 1.66663 10.0001 1.66663C5.39771 1.66663 1.66675 5.39759 1.66675 9.99996C1.66675 14.6023 5.39771 18.3333 10.0001 18.3333Z" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
287 <path d="M13.3334 9.99996L10.0001 6.66663L6.66675 9.99996" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
288 <path d="M10 13.3333V6.66663" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
289 </g>
290 <defs>
291 <clipPath id="clip0_1244_36215">
292 <rect width="20" height="20" fill="white"></rect>
293 </clipPath>
294 </defs>
295 </svg> <?php esc_html_e('This feature is available on paid subscription.', 'nitropack'); ?> <a href="https://app.nitropack.io/subscription/buy" class="text-primary" target="_blank"><b><?php esc_html_e('Upgrade here', 'nitropack'); ?></b></a>
296 </p>
297 </div>
298 <?php endif; ?>
299 </div>
300 <div class="nitro-option" id="real-time-stock-refresh-widget">
301 <div class="nitro-option-main">
302 <div class="text-box">
303 <h6><?php esc_html_e('Real-time Stock Refresh', 'nitropack'); ?></h6>
304 <p><?php esc_html_e('Keep accurate product availability on your WooCommerce site. Turn on this feature if you display stock quantities, and enjoy automatic cache clearance when stock decreases.', 'nitropack'); ?></p>
305
306 </div>
307 <label class="inline-flex items-center cursor-pointer ml-auto">
308 <input type="checkbox" id="woo-stock-reduce-status" class="sr-only peer" <?php echo (int)$stockReduceStatus === 1 ? "checked" : ""; ?>>
309 <div class="toggle"></div>
310 </label>
311 </div>
312 </div>
313 <?php } ?>
314
315 </div>
316 </div>
317 <div class="card-footer disconnect-container">
318 <a class="text-primary btn-link" id="disconnect-btn"><?php esc_html_e('Disconnect NitroPack plugin', 'nitropack'); ?></a>
319 <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-disconnect.php'; ?>
320 </div>
321 </div>
322 <!-- Basic Settings Card End -->
323 <!-- Go to app Card -->
324 <div class="card app-card">
325 <div class="card-body">
326 <div class="flex items-center justify-between">
327 <p><?php esc_html_e('You can further configure how NitroPack\'s optimization behaves through your account', 'nitropack'); ?>.</p>
328 <?php
329 function getNitropackDashboardUrl() {
330 $siteId = nitropack_get_current_site_id();
331 $dashboardUrl = 'https://app.nitropack.io/dashboard';
332
333 if ($siteId !== null) {
334 $dashboardUrl .= '?update_session_website_id=' . urlencode($siteId);
335 }
336
337 return $dashboardUrl;
338 }
339 ?>
340 <a href="<?php echo esc_url(getNitropackDashboardUrl()); ?>" target="_blank" class="btn btn-primary ml-2 flex-shrink-0"><?php esc_html_e('Go to app', 'nitropack'); ?></a>
341 </div>
342 </div>
343 </div>
344 <!-- Go to app card End -->
345 </div>
346 <?php $notOptimizedCPTs = nitropack_filter_non_optimized();
347 if (!get_option('nitropack-noticeOptimizeCPT') && !empty($notOptimizedCPTs)) require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-not-optimized-CPT.php'; ?>
348 </div>
349 <?php require_once NITROPACK_PLUGIN_DIR . 'view/modals/modal-unsaved-changes.php'; ?>
350 <script>
351 ($ => {
352 var getOptimizationsTimeout = null;
353 let isClearing = false;
354 var paid_plan = false;
355 $(window).on("load", function() {
356 getOptimizations();
357 getPlan();
358 <?php if ($checkedCompression != 1) { ?>
359 autoDetectCompression();
360 <?php } ?>
361 });
362
363 /* Cache Purge begin */
364 window.performCachePurge = () => {
365 purgeCache();
366 }
367
368 let purgeCache = () => {
369 let purgeEvent = new Event("cache.purge.request");
370 window.dispatchEvent(purgeEvent);
371 }
372
373 var getOptimizations = _ => {
374 var url = '<?php echo $optimizationDetailsUrl; ?>';
375 ((s, e, f) => {
376 if (window.fetch) {
377 fetch(url)
378 .then(resp => resp.json())
379 .then(s)
380 .catch(e)
381 .finally(f);
382 } else {
383 $.ajax({
384 url: url,
385 type: 'GET',
386 dataType: 'json',
387 success: s,
388 error: e,
389 complete: f
390 })
391 }
392 })(data => {
393 $('[data-last-cache-purge]').text(data.last_cache_purge.timeAgo);
394 if (data.last_cache_purge.reason) {
395 $('[data-purge-reason]').text(data.last_cache_purge.reason);
396 $('[data-purge-reason]').attr('title', data.last_cache_purge.reason);
397 $('#last-cache-purge-reason').show();
398 } else {
399 $('#last-cache-purge-reason').hide();
400 }
401 if (data.pending_count) {
402 $("#pending-optimizations-count").text(data.pending_count);
403 $("#pending-optimizations-section").show();
404 } else {
405 $("#pending-optimizations-section").hide();
406 }
407
408 $('[data-optimized-pages-total]').text(data.optimized_pages.total);
409
410 }, __ => {
411 console.error("An error occurred while fetching data for optimized pages");
412 }, __ => {
413 if (!getOptimizationsTimeout) {
414 getOptimizationsTimeout = setTimeout(function() {
415 getOptimizationsTimeout = null;
416 getOptimizations();
417 }, 60000);
418 }
419 });
420 }
421
422 var getPlan = _ => {
423
424 var url = '<?php echo $planDetailsUrl; ?>';
425 ((s, e, f) => {
426 if (window.fetch) {
427 fetch(url)
428 .then(resp => resp.json())
429 .then(s)
430 .catch(e)
431 .finally(f);
432 } else {
433 $.ajax({
434 url: url,
435 type: 'GET',
436 dataType: 'json',
437 success: s,
438 error: e,
439 complete: f
440 })
441 }
442 })(data => {
443
444 $('.plan-name').text(data.plan_title);
445 $('[data-next-billing]').text(data.next_billing ? data.next_billing : 'N/A');
446 $('[data-next-reset]').text(data.next_reset ? data.next_reset : 'N/A');
447 $('[data-page-views]').text(data.page_views ? data.page_views : 'N/A');
448 $('[data-cdn-bandwidth]').text(data.cdn_bandwidth ? data.cdn_bandwidth + ' out of ' + data.max_cdn_bandwidth : 'N/A');
449
450 for (prop in data) {
451 if (prop.indexOf("show_") === 0) continue;
452 if (prop.indexOf("label_") === 0) continue;
453 if (prop.indexOf("max_") === 0) continue;
454 if (
455 typeof data["show_" + prop] != "undefined" &&
456 data["show_" + prop] &&
457 typeof data["label_" + prop] != "undefined" &&
458 typeof data["max_" + prop] != "undefined"
459 ) {
460 let propertyLabel = data["label_" + prop];
461 let propertyValue = data[prop];
462 let propertyLimit = data["max_" + prop];
463 $("#plan-quotas").append('<li class="list-group-item px-0 d-flex justify-content-between align-items-center">' + propertyLabel + ' <span><span data-optimizations>' + propertyValue + '</span> out of <span data-max-optimizations>' + propertyLimit + '</span></span></li>');
464 }
465 }
466
467 }, __ => {
468 NitropackUI.triggerToast('error', '<?php esc_html_e('Error while fetching plan data', 'nitropack'); ?>');
469 }, __ => {});
470 }
471
472
473 $(document).on('click', "#compression-test-btn", e => {
474 e.preventDefault();
475 autoDetectCompression();
476 });
477 /* Compression end */
478
479 /* HTML Compression begin */
480 var autoDetectCompression = function() {
481 let msg_container = $('#compression-widget .msg-container'),
482 msg_icon = msg_container.find('.icon'),
483 msg_box = msg_container.find('.msg'),
484 compression_setting = $('#compression-status'),
485 compression_btn = $('#compression-test-btn');
486 //add spinner here
487 msg_box.html('<img src="<?php echo plugin_dir_url(__FILE__) . 'images/loading.svg'; ?>" alt="loading" class="icon"> <?php esc_html_e('Testing current compression status', 'nitropack'); ?>');
488 compression_btn.addClass('hidden');
489 msg_container.removeClass('hidden');
490 $.post(ajaxurl, {
491 action: 'nitropack_test_compression_ajax',
492 nonce: nitroNonce
493 }, function(response) {
494 var resp = JSON.parse(response);
495
496 if (resp.status == "success") {
497 if (resp.hasCompression) { // compression already enabled
498 compression_setting.attr("checked", false);
499
500 msg_box.text('<?php esc_html_e('Compression is already enabled on your server! There is no need to enable it in NitroPack.', 'nitropack'); ?>')
501 } else {
502 compression_setting.attr("checked", true);
503 msg_box.text('<?php esc_html_e('No compression was detected! We will now enable it in NitroPack.', 'nitropack'); ?>');
504 }
505 NitropackUI.triggerToast(resp.type, resp.message);
506 } else {
507 msg_box.text('<?php esc_html_e('Could not determine compression status automatically. Please configure it manually.', 'nitropack'); ?>');
508 }
509 setTimeout(function() {
510 msg_container.addClass('hidden');
511 compression_btn.removeClass('hidden');
512 }, 5000);
513 });
514 }
515
516
517 $("#compression-status").on("click", function(e) {
518 $.post(ajaxurl, {
519 action: 'nitropack_set_compression_ajax',
520 nonce: nitroNonce,
521 data: {
522 compressionStatus: $(this).is(":checked") ? 1 : 0
523 }
524 }, function(response) {
525 var resp = JSON.parse(response);
526 NitropackUI.triggerToast(resp.type, resp.message);
527 });
528 });
529 $("#can-editor-clear-cache").on("click", function(e) {
530 $.post(ajaxurl, {
531 action: 'nitropack_set_can_editor_clear_cache',
532 nonce: nitroNonce,
533 data: {
534 canEditorClearCache: $(this).is(":checked") ? 1 : 0
535 }
536 }, function(response) {
537 var resp = JSON.parse(response);
538 NitropackUI.triggerToast(resp.type, resp.message);
539 });
540 });
541
542 $("#auto-purge-status").on("click", function(e) {
543 $.post(ajaxurl, {
544 action: 'nitropack_set_auto_cache_purge_ajax',
545 nonce: nitroNonce,
546 autoCachePurgeStatus: $(this).is(":checked") ? 1 : 0
547 }, function(response) {
548 var resp = JSON.parse(response);
549 NitropackUI.triggerToast(resp.type, resp.message);
550 });
551 });
552
553 $("#cart-cache-status").on("click", function(e) {
554 $.post(ajaxurl, {
555 action: 'nitropack_set_cart_cache_ajax',
556 nonce: nitroNonce,
557 cartCacheStatus: $(this).is(":checked") ? 1 : 0
558 }, function(response) {
559 var resp = JSON.parse(response);
560 NitropackUI.triggerToast(resp.type, resp.message);
561 });
562 });
563
564
565 $("#woo-stock-reduce-status").on("click", function(e) {
566 $.post(ajaxurl, {
567 action: 'nitropack_set_stock_reduce_status',
568 nonce: nitroNonce,
569 data: {
570 stockReduceStatus: $(this).is(":checked") ? 1 : 0
571 }
572 }, function(response) {
573 var resp = JSON.parse(response);
574 NitropackUI.triggerToast(resp.type, resp.message);
575 });
576 });
577
578 $("#bb-purge-status").on("click", function(e) {
579 $.post(ajaxurl, {
580 action: 'nitropack_set_bb_cache_purge_sync_ajax',
581 nonce: nitroNonce,
582 bbCachePurgeSyncStatus: $(this).is(":checked") ? 1 : 0
583 }, function(response) {
584 var resp = JSON.parse(response);
585 NitropackUI.triggerToast(resp.type, resp.message);
586 });
587 });
588
589
590 })(jQuery);
591 </script>