| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) exit; |
| 3 |
$berqconfigs = berqConfigs::getInstance(); |
| 4 |
$berqwp_configs = $berqconfigs->get_configs(); |
| 5 |
|
| 6 |
if (get_option('berqwp_enable_sandbox') === false) { |
| 7 |
update_option('berqwp_enable_sandbox', 0, false); |
| 8 |
} |
| 9 |
|
| 10 |
if (get_option('berqwp_webp_max_width') === false) { |
| 11 |
update_option('berqwp_webp_max_width', 1920, false); |
| 12 |
} |
| 13 |
|
| 14 |
if (get_option('berqwp_webp_quality') === false) { |
| 15 |
update_option('berqwp_webp_quality', 70, false); |
| 16 |
} |
| 17 |
|
| 18 |
if (get_option('berqwp_image_lazyloading') === false) { |
| 19 |
update_option('berqwp_image_lazyloading', 1, false); |
| 20 |
} |
| 21 |
|
| 22 |
if (get_option('berqwp_enable_cdn') === false) { |
| 23 |
update_option('berqwp_enable_cdn', 1, false); |
| 24 |
} |
| 25 |
|
| 26 |
if (get_option('berqwp_enable_cwv') === false) { |
| 27 |
update_option('berqwp_enable_cwv', 0, false); |
| 28 |
} |
| 29 |
|
| 30 |
if (get_option('berqwp_preload_fontfaces') === false) { |
| 31 |
update_option('berqwp_preload_fontfaces', 1, false); |
| 32 |
} |
| 33 |
|
| 34 |
if (get_option('berqwp_preload_cookiebanner') === false) { |
| 35 |
update_option('berqwp_preload_cookiebanner', 0, false); |
| 36 |
} |
| 37 |
|
| 38 |
if (get_option('berq_css_optimization') === false) { |
| 39 |
update_option('berq_css_optimization', 'auto', false); |
| 40 |
} |
| 41 |
|
| 42 |
if (get_option('berq_js_optimization') === false) { |
| 43 |
update_option('berq_js_optimization', 'auto', false); |
| 44 |
} |
| 45 |
|
| 46 |
if (get_option('berqwp_disable_emojis') === false) { |
| 47 |
update_option('berqwp_disable_emojis', 1, false); |
| 48 |
} |
| 49 |
|
| 50 |
if (get_option('berqwp_lazyload_youtube_embed') === false) { |
| 51 |
update_option('berqwp_lazyload_youtube_embed', 1, false); |
| 52 |
} |
| 53 |
|
| 54 |
if (get_option('berqwp_fluid_images') === false) { |
| 55 |
update_option('berqwp_fluid_images', 1, false); |
| 56 |
} |
| 57 |
|
| 58 |
if (get_option('berqwp_preload_yt_poster') === false) { |
| 59 |
update_option('berqwp_preload_yt_poster', 0, false); |
| 60 |
} |
| 61 |
|
| 62 |
if (get_option('berqwp_javascript_execution_mode') === false) { |
| 63 |
update_option('berqwp_javascript_execution_mode', 4, false); |
| 64 |
} |
| 65 |
|
| 66 |
if (get_option('berqwp_interaction_delay') === false) { |
| 67 |
update_option('berqwp_interaction_delay', '', false); |
| 68 |
} |
| 69 |
|
| 70 |
if (get_option('berq_opt_mode') === false) { |
| 71 |
update_option('berq_opt_mode', 2, false); |
| 72 |
} |
| 73 |
|
| 74 |
if (get_option('berqwp_optimize_post_types') === false) { |
| 75 |
update_option('berqwp_optimize_post_types', ['post', 'page', 'product'], false); |
| 76 |
} |
| 77 |
|
| 78 |
// if (get_option('berq_exclude_js_css') === false) { |
| 79 |
// update_option('berq_exclude_js_css', [], false); |
| 80 |
// } |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
if (get_option('berq_exclude_cdn') === false) { |
| 85 |
update_option('berq_exclude_cdn', [], false); |
| 86 |
} |
| 87 |
|
| 88 |
if (get_option('berqwp_optimize_taxonomies') === false) { |
| 89 |
update_option('berqwp_optimize_taxonomies', ['category', 'product_cat'], false); |
| 90 |
} |
| 91 |
|
| 92 |
if (get_option('berq_ignore_urls_params') === false) { |
| 93 |
update_option('berq_ignore_urls_params', ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid', 'msclkid'], false); |
| 94 |
} |
| 95 |
|
| 96 |
// if (empty($berqwp_configs['site_id'])) { |
| 97 |
// $blog_id = get_current_blog_id(); |
| 98 |
// $network_id = function_exists('get_current_network_id') ? get_current_network_id() : 1; |
| 99 |
// $siteurl = get_option('siteurl'); |
| 100 |
// $site_id = md5("berqwp|$network_id|$blog_id|$siteurl"); |
| 101 |
|
| 102 |
// $berqconfigs->update_configs(['site_id' => $site_id]); |
| 103 |
// } |
| 104 |
|
| 105 |
|
| 106 |
// if (get_option('berq_exclude_urls', null) == null) { |
| 107 |
// $exclude_urls = []; |
| 108 |
|
| 109 |
// if (class_exists('WooCommerce')) { |
| 110 |
// // WooCommerce is active |
| 111 |
|
| 112 |
// // Get cart URL |
| 113 |
// $cart_url = wc_get_cart_url(); |
| 114 |
|
| 115 |
// // Get checkout URL |
| 116 |
// $checkout_url = wc_get_checkout_url(); |
| 117 |
|
| 118 |
// $exclude_urls[] = esc_url($cart_url); |
| 119 |
// $exclude_urls[] = esc_url($checkout_url); |
| 120 |
|
| 121 |
// } |
| 122 |
|
| 123 |
// update_option('berq_exclude_urls', $exclude_urls); |
| 124 |
|
| 125 |
// } |
| 126 |
|
| 127 |
if (get_option('berqwp_enable_critical_css') === false) { |
| 128 |
update_option('berqwp_enable_critical_css', 1, false); |
| 129 |
} |
| 130 |
|
| 131 |
if (get_option('berqwp_force_include_critical_css') === false) { |
| 132 |
update_option('berqwp_force_include_critical_css', [], false); |
| 133 |
} |
| 134 |
|
| 135 |
if (!empty(get_option('berq_exclude_js_css'))) { |
| 136 |
$css_js_excludes = get_option('berq_exclude_js_css'); |
| 137 |
update_option('berqwp_exclude_css', $css_js_excludes, false); |
| 138 |
update_option('berqwp_exclude_js', $css_js_excludes, false); |
| 139 |
|
| 140 |
delete_option('berq_exclude_js_css'); |
| 141 |
} |
| 142 |
|
| 143 |
if (get_option('berqwp_exclude_css') === false) { |
| 144 |
update_option('berqwp_exclude_css', [], false); |
| 145 |
} |
| 146 |
|
| 147 |
if (get_option('berqwp_exclude_js') === false) { |
| 148 |
update_option('berqwp_exclude_js', [], false); |
| 149 |
} |
| 150 |
|
| 151 |
if (get_option('berqwp_exclude_third_party_js') === false) { |
| 152 |
update_option('berqwp_exclude_third_party_js', [], false); |
| 153 |
} |
| 154 |
|
| 155 |
if (get_option('berqwp_async_excluded_styles') === false) { |
| 156 |
update_option('berqwp_async_excluded_styles', 0, false); |
| 157 |
} |
| 158 |
|
| 159 |
if (get_option('berqwp_defer_excluded_styles') === false) { |
| 160 |
update_option('berqwp_defer_excluded_styles', 1, false); |
| 161 |
} |
| 162 |
|
| 163 |
if (get_option('berqwp_defer_excluded_js') === false) { |
| 164 |
update_option('berqwp_defer_excluded_js', 1, false); |
| 165 |
} |
| 166 |
|
| 167 |
if (get_option('berqwp_delay_third_party_scripts') === false) { |
| 168 |
update_option('berqwp_delay_third_party_scripts', 0, false); |
| 169 |
} |
| 170 |
|
| 171 |
if (get_option('berqwp_lazy_render') === false) { |
| 172 |
update_option('berqwp_lazy_render', 0, false); |
| 173 |
} |
| 174 |
|
| 175 |
if (get_option('berqwp_prerender_on_hover') === false) { |
| 176 |
update_option('berqwp_prerender_on_hover', 1, false); |
| 177 |
} |
| 178 |
|
| 179 |
if (get_option('berqwp_enable_webp') === false) { |
| 180 |
|
| 181 |
$bwp_enable_webp = 1; |
| 182 |
if (get_option('berqwp_disable_webp') !== false) { |
| 183 |
$bwp_enable_webp = !get_option('berqwp_disable_webp'); |
| 184 |
delete_option('berqwp_disable_webp'); |
| 185 |
} |
| 186 |
|
| 187 |
update_option('berqwp_enable_webp', (int) $bwp_enable_webp, false); |
| 188 |
} |
| 189 |
|
| 190 |
if (get_option('berqwp_exclude_lazy_load_images') === false) { |
| 191 |
update_option('berqwp_exclude_lazy_load_images', [], false); |
| 192 |
} |
| 193 |
|
| 194 |
if (get_option('berqwp_lazy_load_videos') === false) { |
| 195 |
update_option('berqwp_lazy_load_videos', 1, false); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
if (get_option('berq_exclude_urls') === false) { |
| 200 |
$urls = get_option('berq_exclude_urls', []); |
| 201 |
|
| 202 |
if (class_exists('WooCommerce')) { |
| 203 |
$page_excludes = [ |
| 204 |
wc_get_cart_url(), |
| 205 |
wc_get_checkout_url(), |
| 206 |
trailingslashit(wc_get_cart_url()), |
| 207 |
trailingslashit(wc_get_checkout_url()), |
| 208 |
]; |
| 209 |
|
| 210 |
$page_excludes = array_unique($page_excludes); |
| 211 |
|
| 212 |
$page_excludes = array_filter($page_excludes, function ($url) use ($urls) { |
| 213 |
return !empty($url) && !in_array($url, $urls) && $url !== trailingslashit(home_url()); |
| 214 |
}); |
| 215 |
|
| 216 |
$should_update = !empty($page_excludes); |
| 217 |
$urls = array_merge($urls, $page_excludes); |
| 218 |
|
| 219 |
|
| 220 |
// if (!empty($cart_url) && !in_array($cart_url, $urls) && trailingslashit($cart_url) !== trailingslashit(home_url())) { |
| 221 |
// $urls[] = esc_url($cart_url); |
| 222 |
// $should_update = true; |
| 223 |
// } |
| 224 |
|
| 225 |
// if (!empty($checkout_url) && !in_array($checkout_url, $urls) && trailingslashit($checkout_url) !== trailingslashit(home_url())) { |
| 226 |
// $urls[] = esc_url($checkout_url); |
| 227 |
// $should_update = true; |
| 228 |
// } |
| 229 |
|
| 230 |
if ($should_update) { |
| 231 |
$berqconfigs->update_configs(['exclude_urls' => $urls]); |
| 232 |
update_option('berq_exclude_urls', $urls, false); |
| 233 |
|
| 234 |
} |
| 235 |
|
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
if (!empty(get_option('berqwp_optimize_queue'))) { |
| 241 |
delete_option('berqwp_optimize_queue'); |
| 242 |
} |