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

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