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