| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) |
| 4 |
exit; |
| 5 |
|
| 6 |
if (isset($_POST['berqwp_save_nonce'])) { |
| 7 |
if (!wp_verify_nonce($_POST['berqwp_save_nonce'], 'berqwp_save_settings')) { |
| 8 |
die('Invalid nonce value'); |
| 9 |
} |
| 10 |
|
| 11 |
if (!empty($_POST['berqwp_license_key'])) { |
| 12 |
if (berq_is_localhost() && get_site_url() !== 'http://berq-test.local') { |
| 13 |
return; |
| 14 |
} |
| 15 |
|
| 16 |
$key = sanitize_text_field($_POST['berqwp_license_key']); |
| 17 |
$key_response = $this->verify_license_key($key, 'slm_activate'); |
| 18 |
|
| 19 |
if (!empty($key_response) && $key_response->result == 'success') { |
| 20 |
update_option('berqwp_license_key', $key); |
| 21 |
|
| 22 |
global $berqNotifications; |
| 23 |
$berqNotifications->success('BerqWP license key has been activated.'); |
| 24 |
|
| 25 |
?> |
| 26 |
<script> |
| 27 |
location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>'; |
| 28 |
</script> |
| 29 |
<?php |
| 30 |
exit(); |
| 31 |
} elseif ($key_response->result == 'error') { |
| 32 |
$error = $key_response->message; |
| 33 |
|
| 34 |
global $berqNotifications; |
| 35 |
$berqNotifications->error($error); |
| 36 |
|
| 37 |
?> |
| 38 |
<script> |
| 39 |
location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>'; |
| 40 |
</script> |
| 41 |
<?php |
| 42 |
exit(); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if (isset($_POST['berqwp_enable_sandbox'])) { |
| 47 |
update_option('berqwp_enable_sandbox', 1); |
| 48 |
} else { |
| 49 |
update_option('berqwp_enable_sandbox', 0); |
| 50 |
} |
| 51 |
|
| 52 |
if (isset($_POST['berqwp_enable_cache_for_loggedin'])) { |
| 53 |
update_option('berqwp_enable_cache_for_loggedin', 1); |
| 54 |
} else { |
| 55 |
update_option('berqwp_enable_cache_for_loggedin', 0); |
| 56 |
} |
| 57 |
|
| 58 |
if (isset($_POST['berqwp_cache_lifespan'])) { |
| 59 |
$val = (int) sanitize_text_field($_POST['berqwp_cache_lifespan']); |
| 60 |
update_option('berqwp_cache_lifespan', $val); |
| 61 |
} |
| 62 |
|
| 63 |
if (isset($_POST['berqwp_webp_max_width'])) { |
| 64 |
$val = (int) sanitize_text_field($_POST['berqwp_webp_max_width']); |
| 65 |
update_option('berqwp_webp_max_width', $val); |
| 66 |
} |
| 67 |
|
| 68 |
if (isset($_POST['berqwp_webp_quality'])) { |
| 69 |
$val = (int) sanitize_text_field($_POST['berqwp_webp_quality']); |
| 70 |
update_option('berqwp_webp_quality', $val); |
| 71 |
} |
| 72 |
|
| 73 |
if (isset($_POST['berqwp_image_lazyloading'])) { |
| 74 |
update_option('berqwp_image_lazyloading', 1); |
| 75 |
} else { |
| 76 |
update_option('berqwp_image_lazyloading', 0); |
| 77 |
} |
| 78 |
|
| 79 |
if (isset($_POST['berqwp_disable_webp'])) { |
| 80 |
update_option('berqwp_disable_webp', 1); |
| 81 |
} else { |
| 82 |
update_option('berqwp_disable_webp', 0); |
| 83 |
} |
| 84 |
|
| 85 |
if (isset($_POST['berqwp_enable_cdn'])) { |
| 86 |
update_option('berqwp_enable_cdn', 1); |
| 87 |
} else { |
| 88 |
update_option('berqwp_enable_cdn', 0); |
| 89 |
} |
| 90 |
|
| 91 |
if (isset($_POST['berqwp_preload_fontfaces'])) { |
| 92 |
update_option('berqwp_preload_fontfaces', 1); |
| 93 |
} else { |
| 94 |
update_option('berqwp_preload_fontfaces', 0); |
| 95 |
} |
| 96 |
|
| 97 |
if (isset($_POST['berqwp_disable_emojis'])) { |
| 98 |
update_option('berqwp_disable_emojis', 1); |
| 99 |
} else { |
| 100 |
update_option('berqwp_disable_emojis', 0); |
| 101 |
} |
| 102 |
|
| 103 |
if (isset($_POST['berqwp_lazyload_youtube_embed'])) { |
| 104 |
update_option('berqwp_lazyload_youtube_embed', 1); |
| 105 |
} else { |
| 106 |
update_option('berqwp_lazyload_youtube_embed', 0); |
| 107 |
} |
| 108 |
|
| 109 |
if (isset($_POST['berqwp_javascript_execution_mode'])) { |
| 110 |
$val = (int) sanitize_text_field($_POST['berqwp_javascript_execution_mode']); |
| 111 |
update_option('berqwp_javascript_execution_mode', $val); |
| 112 |
} |
| 113 |
|
| 114 |
$_POST['berqwp_optimize_post_types'] = $_POST['berqwp_optimize_post_types'] ?? []; |
| 115 |
if (isset($_POST['berqwp_optimize_post_types']) && is_array($_POST['berqwp_optimize_post_types'])) { |
| 116 |
update_option('berqwp_optimize_post_types', $_POST['berqwp_optimize_post_types']); |
| 117 |
} |
| 118 |
|
| 119 |
$_POST['berqwp_optimize_taxonomies'] = $_POST['berqwp_optimize_taxonomies'] ?? []; |
| 120 |
if (isset($_POST['berqwp_optimize_taxonomies']) && is_array($_POST['berqwp_optimize_taxonomies'])) { |
| 121 |
update_option('berqwp_optimize_taxonomies', $_POST['berqwp_optimize_taxonomies']); |
| 122 |
} |
| 123 |
|
| 124 |
if (isset($_POST['berqwp_interaction_delay'])) { |
| 125 |
$val = sanitize_text_field($_POST['berqwp_interaction_delay']); |
| 126 |
update_option('berqwp_interaction_delay', $val); |
| 127 |
} |
| 128 |
|
| 129 |
if (isset($_POST['berq_opt_mode'])) { |
| 130 |
|
| 131 |
$val = sanitize_text_field($_POST['berq_opt_mode']); |
| 132 |
|
| 133 |
if ($val !== get_option( 'berq_opt_mode' )) { |
| 134 |
do_action( 'berqwp_before_update_optimization_mode' ); |
| 135 |
} |
| 136 |
|
| 137 |
update_option('berq_opt_mode', $val); |
| 138 |
} |
| 139 |
|
| 140 |
if (isset($_POST['berqwp_enable_preload_mostly_used_font'])) { |
| 141 |
update_option('berqwp_enable_preload_mostly_used_font', 1); |
| 142 |
} else { |
| 143 |
update_option('berqwp_enable_preload_mostly_used_font', 0); |
| 144 |
} |
| 145 |
|
| 146 |
/*if (!empty($_POST['berqwp_license_key'])) { |
| 147 |
if (berq_is_localhost()) { |
| 148 |
return; |
| 149 |
} |
| 150 |
$key = sanitize_text_field($_POST['berqwp_license_key']); |
| 151 |
$key_response = $this->verify_license_key($key, 'slm_activate'); |
| 152 |
|
| 153 |
|
| 154 |
if (!empty($key_response) && $key_response->result == 'success') { |
| 155 |
update_option('berqwp_license_key', $key); |
| 156 |
delete_transient( 'berq_lic_response_cache' ); |
| 157 |
|
| 158 |
} elseif ($key_response->result == 'error') { |
| 159 |
$error = $key_response->message; |
| 160 |
?> |
| 161 |
<div class="notice notice-error is-dismissible"> |
| 162 |
<?php echo $error; ?> |
| 163 |
</div> |
| 164 |
<?php |
| 165 |
} |
| 166 |
}*/ |
| 167 |
|
| 168 |
if (!empty($_POST['berq_deactivate_key'])) { |
| 169 |
$license_key = get_option('berqwp_license_key'); |
| 170 |
$key_response = $this->verify_license_key($license_key, 'slm_deactivate'); |
| 171 |
|
| 172 |
delete_transient('berq_lic_response_cache'); |
| 173 |
delete_option('berqwp_license_key'); |
| 174 |
// if (!empty($key_response) && $key_response->result == 'success') { |
| 175 |
// } |
| 176 |
|
| 177 |
global $berqNotifications; |
| 178 |
$berqNotifications->success('BerqWP license key has been deactivated.'); |
| 179 |
|
| 180 |
?> |
| 181 |
<script> |
| 182 |
location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>'; |
| 183 |
</script> |
| 184 |
<?php |
| 185 |
exit; |
| 186 |
} |
| 187 |
|
| 188 |
if (isset($_POST['berq_exclude_urls'])) { |
| 189 |
$urls = sanitize_textarea_field($_POST['berq_exclude_urls']); |
| 190 |
$urls_array = explode("\n", $urls); |
| 191 |
|
| 192 |
// Add trailing slash to each URL |
| 193 |
$urls_array = array_map(function ($url) { |
| 194 |
if (!empty ($url)) { |
| 195 |
return trailingslashit(trim($url)); |
| 196 |
} |
| 197 |
}, $urls_array); |
| 198 |
|
| 199 |
if (isset($urls_array)) { |
| 200 |
update_option('berq_exclude_urls', $urls_array); |
| 201 |
} |
| 202 |
|
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
if (!empty($_POST['berq_ignore_urls_params'])) { |
| 207 |
$urls = sanitize_textarea_field($_POST['berq_ignore_urls_params']); |
| 208 |
$urls_array = explode("\n", $urls); |
| 209 |
|
| 210 |
if (!empty($urls_array)) { |
| 211 |
update_option('berq_ignore_urls_params', $urls_array); |
| 212 |
} |
| 213 |
|
| 214 |
} |
| 215 |
|
| 216 |
if (isset($_POST['berq_exclude_js_css'])) { |
| 217 |
$urls = sanitize_textarea_field($_POST['berq_exclude_js_css']); |
| 218 |
$urls_array = explode("\n", $urls); |
| 219 |
|
| 220 |
if (isset($urls_array)) { |
| 221 |
update_option('berq_exclude_js_css', $urls_array); |
| 222 |
} |
| 223 |
|
| 224 |
} |
| 225 |
|
| 226 |
global $berqNotifications; |
| 227 |
$berqNotifications->success('Changes have been saved! Please flush the cache to make changes visible for the visitors.'); |
| 228 |
|
| 229 |
|
| 230 |
?> |
| 231 |
<script> |
| 232 |
location.href = '<?php echo esc_html(get_admin_url() . 'admin.php?page=berqwp'); ?>'; |
| 233 |
</script> |
| 234 |
<?php |
| 235 |
exit; |
| 236 |
|
| 237 |
} |
| 238 |
|