PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 4.0.29
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v4.0.29
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.29, at admin/save-settings.php

845 lines 28.1 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_on_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 the option is changed require flush cache
486 if (bwp_is_option_updated('berqwp_enable_critical_css')) {
487 $berq_log->info('Updated berqwp_enable_critical_css');
488 update_option('bwp_require_flush_cache', 1);
489 }
490
491 if (isset($_POST['berqwp_enable_critical_css'])) {
492 update_option('berqwp_enable_critical_css', 1);
493 } else {
494 update_option('berqwp_enable_critical_css', 0);
495 }
496
497 // If the option is changed require flush cache
498 if (bwp_is_option_updated('berqwp_enable_used_css')) {
499 $berq_log->info('Updated berqwp_enable_used_css');
500 update_option('bwp_require_flush_cache', 1);
501 }
502
503 if (isset($_POST['berqwp_enable_used_css'])) {
504 update_option('berqwp_enable_used_css', 1);
505 } else {
506 update_option('berqwp_enable_used_css', 0);
507 }
508
509 if (isset($_POST['berqwp_async_excluded_styles'])) {
510 update_option('berqwp_async_excluded_styles', 1);
511 } else {
512 update_option('berqwp_async_excluded_styles', 0);
513 }
514
515 // if (isset($_POST['berqwp_defer_excluded_styles'])) {
516 // update_option('berqwp_defer_excluded_styles', 1);
517 // } else {
518 // update_option('berqwp_defer_excluded_styles', 0);
519 // }
520
521 if (isset($_POST['berqwp_delay_third_party_scripts'])) {
522 update_option('berqwp_delay_third_party_scripts', 1);
523 } else {
524 update_option('berqwp_delay_third_party_scripts', 0);
525 }
526
527 if (isset($_POST['berqwp_lazy_render'])) {
528 update_option('berqwp_lazy_render', 1);
529 } else {
530 update_option('berqwp_lazy_render', 0);
531 }
532
533 if (isset($_POST['berqwp_enable_webp'])) {
534 update_option('berqwp_enable_webp', 1);
535 } else {
536 update_option('berqwp_enable_webp', 0);
537 }
538
539 if (isset($_POST['berqwp_prerender_on_hover'])) {
540 update_option('berqwp_prerender_on_hover', 1);
541 } else {
542 update_option('berqwp_prerender_on_hover', 0);
543 }
544
545 if (isset($_POST['berqwp_lazy_load_videos'])) {
546 update_option('berqwp_lazy_load_videos', 1);
547 } else {
548 update_option('berqwp_lazy_load_videos', 0);
549 }
550
551 if (isset($_POST['berqwp_force_include_critical_css'])) {
552 $keywords = sanitize_textarea_field($_POST['berqwp_force_include_critical_css']);
553 $keywords = explode("\n", $keywords);
554
555 $keywords = array_map(function ($kw) {
556 return trim($kw);
557 }, $keywords);
558
559 $keywords = array_filter($keywords, function ($kw) {
560 return !empty($kw);
561 });
562
563 if (bwp_is_option_updated('berqwp_force_include_critical_css')) {
564
565 update_option('bwp_require_flush_cache', 1);
566 }
567
568 update_option('berqwp_force_include_critical_css', $keywords);
569 }
570
571 if (isset($_POST['berqwp_exclude_lazy_load_images'])) {
572 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_lazy_load_images']);
573 $keywords = explode("\n", $keywords);
574
575 $keywords = array_map(function ($kw) {
576 return trim($kw);
577 }, $keywords);
578
579 $keywords = array_filter($keywords, function ($kw) {
580 return !empty($kw);
581 });
582
583 if (bwp_is_option_updated('berqwp_exclude_lazy_load_images')) {
584
585 update_option('bwp_require_flush_cache', 1);
586 }
587
588 update_option('berqwp_exclude_lazy_load_images', $keywords);
589 }
590
591 if (isset($_POST['berqwp_exclude_third_party_js'])) {
592 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_third_party_js']);
593 $keywords = explode("\n", $keywords);
594
595 $keywords = array_map(function ($kw) {
596 return trim($kw);
597 }, $keywords);
598
599 $keywords = array_filter($keywords, function ($kw) {
600 return !empty($kw);
601 });
602
603 if (bwp_is_option_updated('berqwp_exclude_third_party_js')) {
604
605 update_option('bwp_require_flush_cache', 1);
606 }
607
608 update_option('berqwp_exclude_third_party_js', $keywords);
609 }
610
611 if (isset($_POST['berqwp_exclude_js'])) {
612 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_js']);
613 $keywords = explode("\n", $keywords);
614
615 $keywords = array_map(function ($kw) {
616 return trim($kw);
617 }, $keywords);
618
619 $keywords = array_filter($keywords, function ($kw) {
620 return !empty($kw);
621 });
622
623 if (bwp_is_option_updated('berqwp_exclude_js')) {
624
625 update_option('bwp_require_flush_cache', 1);
626 }
627
628 update_option('berqwp_exclude_js', $keywords);
629 }
630
631 if (isset($_POST['berqwp_exclude_css'])) {
632 $keywords = sanitize_textarea_field($_POST['berqwp_exclude_css']);
633 $keywords = explode("\n", $keywords);
634
635 $keywords = array_map(function ($kw) {
636 return trim($kw);
637 }, $keywords);
638
639 $keywords = array_filter($keywords, function ($kw) {
640 return !empty($kw);
641 });
642
643 if (bwp_is_option_updated('berqwp_exclude_css')) {
644
645 update_option('bwp_require_flush_cache', 1);
646 }
647
648 update_option('berqwp_exclude_css', $keywords);
649 }
650
651 // If the option is changed require flush cache
652 if (bwp_is_option_updated('berqwp_javascript_execution_mode')) {
653 $berq_log->info('Updated berqwp_javascript_execution_mode');
654 update_option('bwp_require_flush_cache', 1);
655 }
656
657 if (isset($_POST['berqwp_javascript_execution_mode'])) {
658 $val = (int) sanitize_text_field($_POST['berqwp_javascript_execution_mode']);
659 update_option('berqwp_javascript_execution_mode', $val);
660 }
661
662 $_POST['berqwp_optimize_post_types'] = $_POST['berqwp_optimize_post_types'] ?? [];
663 if (isset($_POST['berqwp_optimize_post_types']) && is_array($_POST['berqwp_optimize_post_types'])) {
664 update_option('berqwp_optimize_post_types', $_POST['berqwp_optimize_post_types']);
665 }
666
667 $_POST['berqwp_optimize_taxonomies'] = $_POST['berqwp_optimize_taxonomies'] ?? [];
668 if (isset($_POST['berqwp_optimize_taxonomies']) && is_array($_POST['berqwp_optimize_taxonomies'])) {
669 update_option('berqwp_optimize_taxonomies', $_POST['berqwp_optimize_taxonomies']);
670 }
671
672 if (isset($_POST['berqwp_interaction_delay'])) {
673 $val = sanitize_text_field($_POST['berqwp_interaction_delay']);
674 update_option('berqwp_interaction_delay', $val);
675 }
676
677 if (isset($_POST['berq_opt_mode'])) {
678
679 $val = sanitize_text_field($_POST['berq_opt_mode']);
680 $current_val = get_option( 'berq_opt_mode' );
681
682 update_option('berq_opt_mode', $val);
683
684 if ($val !== $current_val) {
685 do_action( 'berqwp_on_update_optimization_mode' );
686 delete_option( 'bwp_require_flush_cache' );
687 }
688 }
689
690 if (isset($_POST['berq_exclude_cdn'])) {
691 $keywords = sanitize_textarea_field($_POST['berq_exclude_cdn']);
692 $keywords = explode("\n", $keywords);
693
694 $keywords = array_map(function ($kw) {
695 return trim($kw);
696 }, $keywords);
697
698 $keywords = array_filter($keywords, function ($kw) {
699 return !empty($kw);
700 });
701
702 if (bwp_is_option_updated('berq_exclude_cdn')) {
703 $berq_log->info('Updated berq_exclude_cdn');
704
705 update_option('bwp_require_flush_cache', 1);
706 }
707
708 update_option('berq_exclude_cdn', $keywords);
709 }
710
711 if (isset($_POST['berq_exclude_urls'])) {
712 $urls = sanitize_textarea_field($_POST['berq_exclude_urls']);
713 $urls_array = explode("\n", $urls);
714
715 // Add trailing slash to each URL
716 $urls_array = array_map(function ($url) {
717 if (!empty ($url)) {
718 $url = trim($url);
719
720 // Delete cache for this url
721 // berqCache::delete_page_cache_files(bwp_url_into_path($url));
722 berqCache::purge_page($url);
723
724 return $url;
725 }
726 }, $urls_array);
727
728 $urls_array = array_filter($urls_array, function($item) {
729 return !empty($item);
730 });
731
732 $urls_array = array_unique($urls_array);
733
734 if (empty($urls_array)) {
735 $urls_array = [];
736 }
737
738 $berqconfigs = berqConfigs::getInstance();
739 $berqconfigs->update_configs(['exclude_urls'=>$urls_array]);
740
741 if (isset($urls_array)) {
742 update_option('berq_exclude_urls', $urls_array);
743 }
744
745 }
746
747
748 if (!empty($_POST['berq_ignore_urls_params'])) {
749 $urls = sanitize_textarea_field($_POST['berq_ignore_urls_params']);
750 $urls_array = explode("\n", $urls);
751
752 if (!empty($urls_array)) {
753 update_option('berq_ignore_urls_params', $urls_array);
754 }
755
756 }
757
758 if (isset($_POST['berq_exclude_cookies'])) {
759 $cookie_ids = sanitize_textarea_field($_POST['berq_exclude_cookies']);
760 // $cookie_ids_array = explode("\n", $cookie_ids);
761 $cookie_ids_array = preg_split("/\r\n|\n|\r/", trim($cookie_ids));
762
763 if (isset($cookie_ids_array) && is_array($cookie_ids_array)) {
764 $berqconfigs = berqConfigs::getInstance();
765 $berqconfigs->update_configs(['exclude_cookies'=>$cookie_ids_array]);
766 }
767
768 }
769
770 if (!empty($_POST['berqwp_cache_lifespan'])) {
771 $cache_lifespan = (int) sanitize_textarea_field($_POST['berqwp_cache_lifespan']);
772
773 // Sanitize
774 if (!in_array($cache_lifespan, [MONTH_IN_SECONDS, WEEK_IN_SECONDS, DAY_IN_SECONDS])) {
775 $cache_lifespan = MONTH_IN_SECONDS;
776 }
777
778 // Update settings
779 $berqconfigs = berqConfigs::getInstance();
780 $berqconfigs->update_configs(['cache_lifespan'=>$cache_lifespan]);
781
782 }
783
784 // If the option is changed require flush cache
785 if (bwp_is_option_updated('berq_exclude_js_css')) {
786 $berq_log->info('Updated berq_exclude_js_css');
787 update_option('bwp_require_flush_cache', 1);
788 }
789
790 if (isset($_POST['berq_exclude_js_css'])) {
791 $urls = sanitize_textarea_field($_POST['berq_exclude_js_css']);
792 $urls_array = explode("\n", $urls);
793
794 $urls_array = array_map(function ($kw) {
795 return trim($kw);
796 }, $urls_array);
797
798 $urls_array = array_filter($urls_array, function ($kw) {
799 return !empty($kw);
800 });
801
802 update_option('berq_exclude_js_css', $urls_array);
803
804 }
805
806 // If the option is changed require flush cache
807 if (bwp_is_option_updated('berq_css_optimization')) {
808 $berq_log->info('Updated berq_css_optimization');
809 update_option('bwp_require_flush_cache', 1);
810 }
811
812 if (!empty($_POST['berq_css_optimization'])) {
813 $css_optimization = sanitize_textarea_field($_POST['berq_css_optimization']);
814 update_option('berq_css_optimization', $css_optimization);
815 }
816
817 // If the option is changed require flush cache
818 if (bwp_is_option_updated('berq_js_optimization')) {
819 $berq_log->info('Updated berq_js_optimization');
820 update_option('bwp_require_flush_cache', 1);
821 }
822
823 if (!empty($_POST['berq_js_optimization'])) {
824 $css_optimization = sanitize_textarea_field($_POST['berq_js_optimization']);
825 update_option('berq_js_optimization', $css_optimization);
826 }
827
828 global $berqNotifications;
829 $berqNotifications->success('Changes have been saved.');
830
831 $tab_id = '';
832 if (!empty($_POST['bwp_current_tab_id'])) {
833 $tab_id = "&tab_id=".sanitize_text_field( $_POST['bwp_current_tab_id'] );
834 }
835
836
837 ?>
838 <script>
839 location.href = '<?php echo get_admin_url() . 'admin.php?page=berqwp'.$tab_id; ?>';
840 </script>
841 <?php
842 exit;
843
844 }
845