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

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