PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.0.17
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.0.17
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / admin / save-settings.php

save-settings.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 4.0.17, at admin/save-settings.php

826 lines 27.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use BerqWP\BerqWP;
4
5 if (!defined('ABSPATH'))
6 exit;
7
8 if (isset($_POST['berqwp_save_nonce'])) {
9 if (!wp_verify_nonce($_POST['berqwp_save_nonce'], 'berqwp_save_settings')) {
10 die('Invalid nonce value');
11 }
12
13 $plugin_name = defined('BERQWP_PLUGIN_NAME') ? BERQWP_PLUGIN_NAME : 'BerqWP';
14
15 if (!empty($_POST['berqwp_intro_page']) && !berqwp_is_license_managed_by_network()) {
16 $optimization_method = sanitize_text_field($_POST['berqwp_optimization_method']);
17
18 if ($optimization_method == 'local') {
19 $email = sanitize_email($_POST['berqwp_local_user_email']);
20
21 wp_remote_post(BerqWP::$endpoint."free-user", [
22 'timeout' => 30,
23 'body' => [
24 'email' => $email,
25 'site_url' => get_option('home'),
26 ]
27 ]);
28
29 $berqconfigs = berqConfigs::getInstance();
30 $berqconfigs->update_configs(['optimization_method' => 'local']);
31
32 ?>
33 <script>
34 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
35 </script>
36 <?php
37 exit();
38 }
39
40 if ($optimization_method == 'cloud' && !empty($_POST['berqwp_license_key'])) {
41 $license_key = sanitize_text_field($_POST['berqwp_license_key']);
42 $berqconfigs = berqConfigs::getInstance();
43 $berqwp_configs = $berqconfigs->get_configs();
44 $site_id = $berqwp_configs['site_id'];
45
46 if (empty($site_id)) {
47 $blog_id = get_current_blog_id();
48 $network_id = function_exists('get_current_network_id') ? get_current_network_id() : 1;
49 $siteurl = get_option('siteurl');
50 $site_id = md5("berqwp|$network_id|$blog_id|$siteurl");
51
52 $berqconfigs->update_configs(['site_id' => $site_id]);
53 }
54
55 // $lic_response = wp_remote_post(BerqWP::$endpoint."authenticate", [
56 // 'timeout' => 30,
57 // 'body' => [
58 // 'license_key' => $license_key,
59 // 'site_id' => $site_id,
60 // 'site_url' => home_url(),
61 // ]
62 // ]);
63
64 // if (is_wp_error($lic_response)) {
65 // $error = "Couldn't reach BerqWP server. Please contact support.";
66 // global $berqNotifications;
67 // $berqNotifications->error($error);
68
69 // ?>
70 // <script>
71 // location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
72 // </script>
73 // <?php
74 // exit();
75 // }
76
77 // $lic_body = wp_remote_retrieve_body($lic_response);
78 // $lic_json = json_decode($lic_body);
79
80 $berqWP = \BerqWP::getInstance();
81 $lic_json = $berqWP->authenticate_license($license_key);
82
83 if (empty($lic_json)) {
84 $error = "Couldn't parse BerqWP server response. Please contact support.";
85 global $berqNotifications;
86 $berqNotifications->error($error);
87
88 ?>
89 <script>
90 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
91 </script>
92 <?php
93 exit();
94 }
95
96 if (!empty($lic_json->lic) && !empty($lic_json->secret) && $lic_json->lic->result == 'success' && ($lic_json->lic->message == 'License key activated' || $lic_json->lic->status == 'active')) {
97 berqwp_update_license_key($license_key);
98
99 $berqconfigs->update_configs([
100 'secret' => $lic_json->secret,
101 'optimization_method' => 'cloud'
102 ]);
103
104 berqwp_update_network_option('berqwp_license_cache', $lic_json->lic);
105
106 if ($lic_json->lic->product_ref == 'AppSumo Deal') {
107 update_option('berqwp_can_use_fluid_images', 0, false);
108
109 // sync addons
110 berqwp_sync_addons($license_key, home_url());
111
112 } else {
113 update_option('berqwp_can_use_fluid_images', 1, false);
114 }
115
116 // trigger cache warmup
117 do_action('berqwp_cache_warmup');
118
119 // clear cache from cloud
120 bwp_request_purge_license_key_cache();
121
122 global $berqNotifications;
123 $berqNotifications->success("$plugin_name license key has been activated.");
124
125 ?>
126 <script>
127 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
128 </script>
129 <?php
130 exit();
131
132 } elseif (isset($lic_json->lic->result ) && $lic_json->lic->result == 'error') {
133 $error = $lic_json->lic->message;
134
135 global $berqNotifications;
136 $berqNotifications->error($error);
137
138 ?>
139 <script>
140 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
141 </script>
142 <?php
143 exit();
144 } elseif (isset($lic_json->lic->status) && $lic_json->lic->status == 'expired') {
145 global $berqNotifications;
146 $berqNotifications->error('License key has expired. Please renew your subscription.');
147
148 ?>
149 <script>
150 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
151 </script>
152 <?php
153 exit();
154 }
155
156 global $berqNotifications;
157 $berqNotifications->error('License key verification failed. Please contact support if the issue persists.');
158
159 ?>
160 <script>
161 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
162 </script>
163 <?php
164 exit();
165 }
166 }
167
168 /*if (!empty($_POST['berqwp_license_key']) && !berqwp_is_license_managed_by_network()) {
169 // if (berq_is_localhost() && get_site_url() !== 'http://berq-test.local') {
170 // return;
171 // }
172
173 $key = sanitize_text_field($_POST['berqwp_license_key']);
174 $key_response = $this->verify_license_key($key, 'slm_activate');
175
176 if (!empty($key_response) && $key_response->result == 'success' && ($key_response->message == 'License key activated' || $key_response->status == 'active')) {
177 berqwp_update_license_key($key);
178
179 if ($key_response->product_ref == 'AppSumo Deal') {
180 update_option('berqwp_can_use_fluid_images', 0, false);
181
182 // sync addons
183 berqwp_sync_addons($key, home_url());
184
185 } else {
186 update_option('berqwp_can_use_fluid_images', 1, false);
187 }
188
189 // trigger cache warmup
190 do_action('berqwp_cache_warmup');
191
192 // clear cache from cloud
193 bwp_request_purge_license_key_cache();
194
195 global $berqNotifications;
196 $berqNotifications->success("$plugin_name license key has been activated.");
197
198 ?>
199 <script>
200 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
201 </script>
202 <?php
203 exit();
204 } elseif (isset($key_response->result ) && $key_response->result == 'error') {
205 $error = $key_response->message;
206
207 global $berqNotifications;
208 $berqNotifications->error($error);
209
210 ?>
211 <script>
212 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
213 </script>
214 <?php
215 exit();
216 } elseif (isset($key_response->status) && $key_response->status == 'expired') {
217 global $berqNotifications;
218 $berqNotifications->error('License key has expired. Please renew your subscription.');
219
220 ?>
221 <script>
222 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
223 </script>
224 <?php
225 exit();
226 }
227
228 global $berqNotifications;
229 $berqNotifications->error('License key verification failed. Please contact support if the issue persists.');
230
231 ?>
232 <script>
233 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
234 </script>
235 <?php
236 exit();
237 }*/
238
239 if (!empty($_POST['berq_deactivate_key']) && !berqwp_is_license_managed_by_network()) {
240 $license_key = berqwp_get_license_key();
241 $key_response = $this->verify_license_key($license_key, 'slm_deactivate');
242
243 delete_transient('berq_lic_response_cache');
244 delete_transient('berqwp_lic_response_cache');
245 berqwp_delete_license_key();
246 berqwp_clear_cache_queue();
247
248 global $berqNotifications;
249 $berqNotifications->success("$plugin_name license key has been deactivated.");
250
251 ?>
252 <script>
253 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
254 </script>
255 <?php
256 exit;
257 }
258
259 if (!empty($_POST['bwp_cf_apitoken']) && !empty($_POST['bwp_cf_zoneid']) && !empty($_POST['bwp_cf_email'])) {
260 $apitoken = sanitize_text_field( $_POST['bwp_cf_apitoken'] );
261 $zoneid = sanitize_text_field( $_POST['bwp_cf_zoneid'] );
262 $email = sanitize_text_field( $_POST['bwp_cf_email'] );
263
264 $berqCloudflareAPIHandler = new berqCloudflareAPIHandler($email, $apitoken, $zoneid);
265
266 if ($berqCloudflareAPIHandler->verify_credentials()) {
267 update_option( 'berqwp_cf_creden', [
268 'apitoken' => $apitoken,
269 'zoneid' => $zoneid,
270 'email' => $email,
271 ], false );
272
273 $berqCloudflareAPIHandler->add_rule();
274 $berqCloudflareAPIHandler->purge_all_cache();
275
276 global $berqNotifications;
277 $berqNotifications->success('Cloudflare account connected.');
278
279 ?>
280 <script>
281 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
282 </script>
283 <?php
284 exit();
285
286 } else {
287
288 global $berqNotifications;
289 $berqNotifications->error('Invalid Cloudflare credentials.');
290
291 ?>
292 <script>
293 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
294 </script>
295 <?php
296 exit();
297 }
298 }
299
300 if (!empty($_POST['bwp_disable_cf'])) {
301
302 if (!empty(get_option( 'berqwp_cf_creden' ))) {
303 $email = get_option( 'berqwp_cf_creden' )['email'];
304 $apitoken = get_option( 'berqwp_cf_creden' )['apitoken'];
305 $zoneid = get_option( 'berqwp_cf_creden' )['zoneid'];
306
307 $berqCloudflareAPIHandler = new berqCloudflareAPIHandler($email, $apitoken, $zoneid);
308 $berqCloudflareAPIHandler->purge_all_cache();
309 $berqCloudflareAPIHandler->delete_rule_by_description('BerqWP cache rules');
310
311 delete_option( 'berqwp_cf_creden' );
312 }
313
314 global $berqNotifications;
315 $berqNotifications->success('Cloudflare Edge Cache disabled.');
316
317 ?>
318 <script>
319 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
320 </script>
321 <?php
322 exit();
323 }
324
325 if (!empty($_POST['bwp_disable_page_compression'])) {
326
327 // Update settings
328 $berqconfigs = berqConfigs::getInstance();
329 $berqconfigs->update_configs(['page_compression'=>false]);
330
331 global $berqNotifications;
332 $berqNotifications->success('Page compression has been successfully disabled on your website.');
333
334 ?>
335 <script>
336 location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>';
337 </script>
338 <?php
339 exit();
340 }
341
342 global $berq_log;
343
344 // If the option is changed
345 if (bwp_is_option_updated('berqwp_enable_sandbox') === true) {
346 $berq_log->info('Updated berqwp_enable_sandbox');
347 do_action('berqwp_update_sandbox_mode');
348 }
349
350 if (isset($_POST['berqwp_enable_sandbox'])) {
351 update_option('berqwp_enable_sandbox', 1);
352 } else {
353 update_option('berqwp_enable_sandbox', 0);
354 }
355
356 if (isset($_POST['berqwp_cache_lifespan'])) {
357 $val = (int) sanitize_text_field($_POST['berqwp_cache_lifespan']);
358 update_option('berqwp_cache_lifespan', $val);
359 }
360
361 if (isset($_POST['berqwp_webp_max_width'])) {
362 $val = (int) sanitize_text_field($_POST['berqwp_webp_max_width']);
363 update_option('berqwp_webp_max_width', $val);
364 }
365
366 if (isset($_POST['berqwp_webp_quality'])) {
367 $val = (int) sanitize_text_field($_POST['berqwp_webp_quality']);
368 update_option('berqwp_webp_quality', $val);
369 }
370
371 // If the option is changed require flush cache
372 if (bwp_is_option_updated('berqwp_image_lazyloading') === true) {
373 $berq_log->info('Updated berqwp_image_lazyloading');
374 update_option('bwp_require_flush_cache', 1);
375 }
376
377 if (isset($_POST['berqwp_image_lazyloading'])) {
378 update_option('berqwp_image_lazyloading', 1);
379 } else {
380 update_option('berqwp_image_lazyloading', 0);
381 }
382
383 // If the option is changed require flush cache
384 if (bwp_is_option_updated('berqwp_disable_webp')) {
385 $berq_log->info('Updated berqwp_disable_webp');
386 update_option('bwp_require_flush_cache', 1);
387 }
388
389 if (isset($_POST['berqwp_disable_webp'])) {
390 update_option('berqwp_disable_webp', 1);
391 } else {
392 update_option('berqwp_disable_webp', 0);
393 }
394
395 // If the option is changed require flush cache
396 if (bwp_is_option_updated('berqwp_fluid_images')) {
397 $berq_log->info('Updated berqwp_fluid_images');
398 update_option('bwp_require_flush_cache', 1);
399 }
400
401 if (isset($_POST['berqwp_fluid_images'])) {
402 update_option('berqwp_fluid_images', 1);
403 } else {
404 update_option('berqwp_fluid_images', 0);
405 }
406
407 // If the option is changed require flush cache
408 if (bwp_is_option_updated('berqwp_enable_cdn')) {
409 $berq_log->info('Updated berqwp_enable_cdn');
410 update_option('bwp_require_flush_cache', 1);
411 }
412
413 if (isset($_POST['berqwp_enable_cdn'])) {
414 update_option('berqwp_enable_cdn', 1);
415 } else {
416 update_option('berqwp_enable_cdn', 0);
417 }
418
419 // If the option is changed require flush cache
420 if (bwp_is_option_updated('berqwp_enable_cwv')) {
421 $berq_log->info('Updated berqwp_enable_cwv');
422 update_option('bwp_require_flush_cache', 1);
423 }
424
425 if (isset($_POST['berqwp_enable_cwv'])) {
426 update_option('berqwp_enable_cwv', 1);
427 } else {
428 update_option('berqwp_enable_cwv', 0);
429 }
430
431 // If the option is changed require flush cache
432 if (bwp_is_option_updated('berqwp_preload_cookiebanner')) {
433 $berq_log->info('Updated berqwp_preload_cookiebanner');
434 update_option('bwp_require_flush_cache', 1);
435 }
436
437 if (isset($_POST['berqwp_preload_cookiebanner'])) {
438 update_option('berqwp_preload_cookiebanner', 1);
439 } else {
440 update_option('berqwp_preload_cookiebanner', 0);
441 }
442
443 // If the option is changed require flush cache
444 if (bwp_is_option_updated('berqwp_preload_fontfaces')) {
445 $berq_log->info('Updated berqwp_preload_fontfaces');
446 update_option('bwp_require_flush_cache', 1);
447 }
448
449 if (isset($_POST['berqwp_preload_fontfaces'])) {
450 update_option('berqwp_preload_fontfaces', 1);
451 } else {
452 update_option('berqwp_preload_fontfaces', 0);
453 }
454
455 if (isset($_POST['berqwp_disable_emojis'])) {
456 update_option('berqwp_disable_emojis', 1);
457 } else {
458 update_option('berqwp_disable_emojis', 0);
459 }
460
461 // If the option is changed require flush cache
462 if (bwp_is_option_updated('berqwp_lazyload_youtube_embed')) {
463 $berq_log->info('Updated berqwp_lazyload_youtube_embed');
464 update_option('bwp_require_flush_cache', 1);
465 }
466
467 if (isset($_POST['berqwp_lazyload_youtube_embed'])) {
468 update_option('berqwp_lazyload_youtube_embed', 1);
469 } else {
470 update_option('berqwp_lazyload_youtube_embed', 0);
471 }
472
473 // If the option is changed require flush cache
474 if (bwp_is_option_updated('berqwp_preload_yt_poster')) {
475 $berq_log->info('Updated berqwp_preload_yt_poster');
476 update_option('bwp_require_flush_cache', 1);
477 }
478
479 if (isset($_POST['berqwp_preload_yt_poster'])) {
480 update_option('berqwp_preload_yt_poster', 1);
481 } else {
482 update_option('berqwp_preload_yt_poster', 0);
483 }
484
485 if (isset($_POST['berqwp_enable_critical_css'])) {
486 update_option('berqwp_enable_critical_css', 1);
487 } else {
488 update_option('berqwp_enable_critical_css', 0);
489 }
490
491 if (isset($_POST['berqwp_async_excluded_styles'])) {
492 update_option('berqwp_async_excluded_styles', 1);
493 } else {
494 update_option('berqwp_async_excluded_styles', 0);
495 }
496
497 // if (isset($_POST['berqwp_defer_excluded_styles'])) {
498 // update_option('berqwp_defer_excluded_styles', 1);
499 // } else {
500 // update_option('berqwp_defer_excluded_styles', 0);
501 // }
502
503 if (isset($_POST['berqwp_delay_third_party_scripts'])) {
504 update_option('berqwp_delay_third_party_scripts', 1);
505 } else {
506 update_option('berqwp_delay_third_party_scripts', 0);
507 }
508
509 if (isset($_POST['berqwp_lazy_render'])) {
510 update_option('berqwp_lazy_render', 1);
511 } else {
512 update_option('berqwp_lazy_render', 0);
513 }
514
515 if (isset($_POST['berqwp_enable_webp'])) {
516 update_option('berqwp_enable_webp', 1);
517 } else {
518 update_option('berqwp_enable_webp', 0);
519 }
520
521 if (isset($_POST['berqwp_prerender_on_hover'])) {
522 update_option('berqwp_prerender_on_hover', 1);
523 } else {
524 update_option('berqwp_prerender_on_hover', 0);
525 }
526
527 if (isset($_POST['berqwp_lazy_load_videos'])) {
528 update_option('berqwp_lazy_load_videos', 1);
529 } else {
530 update_option('berqwp_lazy_load_videos', 0);
531 }
532
533 if (isset($_POST['berqwp_force_include_critical_css'])) {
534 $keywords = sanitize_textarea_field($_POST['berqwp_force_include_critical_css']);
535 $keywords = explode("\n", $keywords);
536
537 $keywords = array_map(function ($kw) {
538 return trim($kw);
539 }, $keywords);
540
541 $keywords = array_filter($keywords, function ($kw) {
542 return !empty($kw);
543 });
544
545 if (bwp_is_option_updated('berqwp_force_include_critical_css')) {
546
547 update_option('bwp_require_flush_cache', 1);
548 }
549
550 update_option('berqwp_force_include_critical_css', $keywords);
551 }
552
553 if (isset($_POST['berqwp_exclude_lazy_load_images'])) {
554 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_lazy_load_images']);
555 $keywords = explode("\n", $keywords);
556
557 $keywords = array_map(function ($kw) {
558 return trim($kw);
559 }, $keywords);
560
561 $keywords = array_filter($keywords, function ($kw) {
562 return !empty($kw);
563 });
564
565 if (bwp_is_option_updated('berqwp_exclude_lazy_load_images')) {
566
567 update_option('bwp_require_flush_cache', 1);
568 }
569
570 update_option('berqwp_exclude_lazy_load_images', $keywords);
571 }
572
573 if (isset($_POST['berqwp_exclude_third_party_js'])) {
574 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_third_party_js']);
575 $keywords = explode("\n", $keywords);
576
577 $keywords = array_map(function ($kw) {
578 return trim($kw);
579 }, $keywords);
580
581 $keywords = array_filter($keywords, function ($kw) {
582 return !empty($kw);
583 });
584
585 if (bwp_is_option_updated('berqwp_exclude_third_party_js')) {
586
587 update_option('bwp_require_flush_cache', 1);
588 }
589
590 update_option('berqwp_exclude_third_party_js', $keywords);
591 }
592
593 if (isset($_POST['berqwp_exclude_js'])) {
594 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_js']);
595 $keywords = explode("\n", $keywords);
596
597 $keywords = array_map(function ($kw) {
598 return trim($kw);
599 }, $keywords);
600
601 $keywords = array_filter($keywords, function ($kw) {
602 return !empty($kw);
603 });
604
605 if (bwp_is_option_updated('berqwp_exclude_js')) {
606
607 update_option('bwp_require_flush_cache', 1);
608 }
609
610 update_option('berqwp_exclude_js', $keywords);
611 }
612
613 if (isset($_POST['berqwp_exclude_css'])) {
614 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_css']);
615 $keywords = explode("\n", $keywords);
616
617 $keywords = array_map(function ($kw) {
618 return trim($kw);
619 }, $keywords);
620
621 $keywords = array_filter($keywords, function ($kw) {
622 return !empty($kw);
623 });
624
625 if (bwp_is_option_updated('berqwp_exclude_css')) {
626
627 update_option('bwp_require_flush_cache', 1);
628 }
629
630 update_option('berqwp_exclude_css', $keywords);
631 }
632
633 // If the option is changed require flush cache
634 if (bwp_is_option_updated('berqwp_javascript_execution_mode')) {
635 $berq_log->info('Updated berqwp_javascript_execution_mode');
636 update_option('bwp_require_flush_cache', 1);
637 }
638
639 if (isset($_POST['berqwp_javascript_execution_mode'])) {
640 $val = (int) sanitize_text_field($_POST['berqwp_javascript_execution_mode']);
641 update_option('berqwp_javascript_execution_mode', $val);
642 }
643
644 $_POST['berqwp_optimize_post_types'] = $_POST['berqwp_optimize_post_types'] ?? [];
645 if (isset($_POST['berqwp_optimize_post_types']) && is_array($_POST['berqwp_optimize_post_types'])) {
646 update_option('berqwp_optimize_post_types', $_POST['berqwp_optimize_post_types']);
647 }
648
649 $_POST['berqwp_optimize_taxonomies'] = $_POST['berqwp_optimize_taxonomies'] ?? [];
650 if (isset($_POST['berqwp_optimize_taxonomies']) && is_array($_POST['berqwp_optimize_taxonomies'])) {
651 update_option('berqwp_optimize_taxonomies', $_POST['berqwp_optimize_taxonomies']);
652 }
653
654 if (isset($_POST['berqwp_interaction_delay'])) {
655 $val = sanitize_text_field($_POST['berqwp_interaction_delay']);
656 update_option('berqwp_interaction_delay', $val);
657 }
658
659 if (isset($_POST['berq_opt_mode'])) {
660
661 $val = sanitize_text_field($_POST['berq_opt_mode']);
662
663 if ($val !== get_option( 'berq_opt_mode' )) {
664 do_action( 'berqwp_before_update_optimization_mode' );
665 delete_option( 'bwp_require_flush_cache' );
666 }
667
668 update_option('berq_opt_mode', $val);
669 }
670
671 if (isset($_POST['berq_exclude_cdn'])) {
672 $keywords = sanitize_textarea_field($_POST['berq_exclude_cdn']);
673 $keywords = explode("\n", $keywords);
674
675 $keywords = array_map(function ($kw) {
676 return trim($kw);
677 }, $keywords);
678
679 $keywords = array_filter($keywords, function ($kw) {
680 return !empty($kw);
681 });
682
683 if (bwp_is_option_updated('berq_exclude_cdn')) {
684 $berq_log->info('Updated berq_exclude_cdn');
685
686 update_option('bwp_require_flush_cache', 1);
687 }
688
689 update_option('berq_exclude_cdn', $keywords);
690 }
691
692 if (isset($_POST['berq_exclude_urls'])) {
693 $urls = sanitize_textarea_field($_POST['berq_exclude_urls']);
694 $urls_array = explode("\n", $urls);
695
696 // Add trailing slash to each URL
697 $urls_array = array_map(function ($url) {
698 if (!empty ($url)) {
699 $url = trim($url);
700
701 // Delete cache for this url
702 // berqCache::delete_page_cache_files(bwp_url_into_path($url));
703 berqCache::purge_page($url);
704
705 return $url;
706 }
707 }, $urls_array);
708
709 $urls_array = array_filter($urls_array, function($item) {
710 return !empty($item);
711 });
712
713 $urls_array = array_unique($urls_array);
714
715 if (empty($urls_array)) {
716 $urls_array = [];
717 }
718
719 $berqconfigs = berqConfigs::getInstance();
720 $berqconfigs->update_configs(['exclude_urls'=>$urls_array]);
721
722 if (isset($urls_array)) {
723 update_option('berq_exclude_urls', $urls_array);
724 }
725
726 }
727
728
729 if (!empty($_POST['berq_ignore_urls_params'])) {
730 $urls = sanitize_textarea_field($_POST['berq_ignore_urls_params']);
731 $urls_array = explode("\n", $urls);
732
733 if (!empty($urls_array)) {
734 update_option('berq_ignore_urls_params', $urls_array);
735 }
736
737 }
738
739 if (isset($_POST['berq_exclude_cookies'])) {
740 $cookie_ids = sanitize_textarea_field($_POST['berq_exclude_cookies']);
741 // $cookie_ids_array = explode("\n", $cookie_ids);
742 $cookie_ids_array = preg_split("/\r\n|\n|\r/", trim($cookie_ids));
743
744 if (isset($cookie_ids_array) && is_array($cookie_ids_array)) {
745 $berqconfigs = berqConfigs::getInstance();
746 $berqconfigs->update_configs(['exclude_cookies'=>$cookie_ids_array]);
747 }
748
749 }
750
751 if (!empty($_POST['berqwp_cache_lifespan'])) {
752 $cache_lifespan = (int) sanitize_textarea_field($_POST['berqwp_cache_lifespan']);
753
754 // Sanitize
755 if (!in_array($cache_lifespan, [MONTH_IN_SECONDS, WEEK_IN_SECONDS, DAY_IN_SECONDS])) {
756 $cache_lifespan = MONTH_IN_SECONDS;
757 }
758
759 // Update settings
760 $berqconfigs = berqConfigs::getInstance();
761 $berqconfigs->update_configs(['cache_lifespan'=>$cache_lifespan]);
762
763 }
764
765 // If the option is changed require flush cache
766 if (bwp_is_option_updated('berq_exclude_js_css')) {
767 $berq_log->info('Updated berq_exclude_js_css');
768 update_option('bwp_require_flush_cache', 1);
769 }
770
771 if (isset($_POST['berq_exclude_js_css'])) {
772 $urls = sanitize_textarea_field($_POST['berq_exclude_js_css']);
773 $urls_array = explode("\n", $urls);
774
775 $urls_array = array_map(function ($kw) {
776 return trim($kw);
777 }, $urls_array);
778
779 $urls_array = array_filter($urls_array, function ($kw) {
780 return !empty($kw);
781 });
782
783 update_option('berq_exclude_js_css', $urls_array);
784
785 }
786
787 // If the option is changed require flush cache
788 if (bwp_is_option_updated('berq_css_optimization')) {
789 $berq_log->info('Updated berq_css_optimization');
790 update_option('bwp_require_flush_cache', 1);
791 }
792
793 if (!empty($_POST['berq_css_optimization'])) {
794 $css_optimization = sanitize_textarea_field($_POST['berq_css_optimization']);
795 update_option('berq_css_optimization', $css_optimization);
796 }
797
798 // If the option is changed require flush cache
799 if (bwp_is_option_updated('berq_js_optimization')) {
800 $berq_log->info('Updated berq_js_optimization');
801 update_option('bwp_require_flush_cache', 1);
802 }
803
804 if (!empty($_POST['berq_js_optimization'])) {
805 $css_optimization = sanitize_textarea_field($_POST['berq_js_optimization']);
806 update_option('berq_js_optimization', $css_optimization);
807 }
808
809 global $berqNotifications;
810 $berqNotifications->success('Changes have been saved.');
811
812 $tab_id = '';
813 if (!empty($_POST['bwp_current_tab_id'])) {
814 $tab_id = "&tab_id=".sanitize_text_field( $_POST['bwp_current_tab_id'] );
815 }
816
817
818 ?>
819 <script>
820 location.href = '<?php echo get_admin_url() . 'admin.php?page=berqwp'.$tab_id; ?>';
821 </script>
822 <?php
823 exit;
824
825 }
826