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