| 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_taxonomies') === false) { |
| 75 |
|
| 76 |
$taxonomy_names = get_taxonomies([ |
| 77 |
'public' => true, |
| 78 |
'publicly_queryable' => true, |
| 79 |
'rewrite' => true, |
| 80 |
'show_ui' => true, // optional but useful |
| 81 |
], 'names'); |
| 82 |
|
| 83 |
$taxonomy_names = array_keys($taxonomy_names); |
| 84 |
|
| 85 |
update_option('berqwp_optimize_taxonomies', $taxonomy_names, false); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
if (get_option('berqwp_optimize_post_types') === false) { |
| 90 |
// update_option('berqwp_optimize_post_types', ['post', 'page', 'product'], false); |
| 91 |
|
| 92 |
$post_type_names = get_post_types(array( |
| 93 |
'public' => true, |
| 94 |
'exclude_from_search' => false, |
| 95 |
), 'names'); |
| 96 |
unset($post_type_names['attachment']); |
| 97 |
unset($post_type_names['e-floating-buttons']); |
| 98 |
|
| 99 |
$post_type_names = array_keys($post_type_names); |
| 100 |
$post_type_names = array_merge($post_type_names, ['post', 'page']); |
| 101 |
$post_type_names = array_unique($post_type_names); |
| 102 |
|
| 103 |
$post_type_names = array_filter($post_type_names, function ($slug) { |
| 104 |
// Get a sample post of this type |
| 105 |
$sample = get_posts( [ |
| 106 |
'post_type' => $slug, |
| 107 |
'posts_per_page' => 1, |
| 108 |
'post_status' => 'publish', |
| 109 |
] ); |
| 110 |
|
| 111 |
if ( empty( $sample ) ) { |
| 112 |
return false; |
| 113 |
} |
| 114 |
|
| 115 |
$url = get_permalink( $sample[0]->ID ); |
| 116 |
|
| 117 |
return strpos($url, '?') === false; |
| 118 |
|
| 119 |
}); |
| 120 |
|
| 121 |
update_option('berqwp_optimize_post_types', $post_type_names, false); |
| 122 |
|
| 123 |
} |
| 124 |
|
| 125 |
// if (get_option('berq_exclude_js_css') === false) { |
| 126 |
// update_option('berq_exclude_js_css', [], false); |
| 127 |
// } |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
if (get_option('berq_exclude_cdn') === false) { |
| 132 |
update_option('berq_exclude_cdn', [], false); |
| 133 |
} |
| 134 |
|
| 135 |
if (get_option('berqwp_optimize_taxonomies') === false) { |
| 136 |
update_option('berqwp_optimize_taxonomies', ['category', 'product_cat'], false); |
| 137 |
} |
| 138 |
|
| 139 |
if (get_option('berq_ignore_urls_params') === false) { |
| 140 |
update_option('berq_ignore_urls_params', ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid', 'msclkid'], false); |
| 141 |
} |
| 142 |
|
| 143 |
// if (empty($berqwp_configs['site_id'])) { |
| 144 |
// $blog_id = get_current_blog_id(); |
| 145 |
// $network_id = function_exists('get_current_network_id') ? get_current_network_id() : 1; |
| 146 |
// $siteurl = get_option('siteurl'); |
| 147 |
// $site_id = md5("berqwp|$network_id|$blog_id|$siteurl"); |
| 148 |
|
| 149 |
// $berqconfigs->update_configs(['site_id' => $site_id]); |
| 150 |
// } |
| 151 |
|
| 152 |
|
| 153 |
// if (get_option('berq_exclude_urls', null) == null) { |
| 154 |
// $exclude_urls = []; |
| 155 |
|
| 156 |
// if (class_exists('WooCommerce')) { |
| 157 |
// // WooCommerce is active |
| 158 |
|
| 159 |
// // Get cart URL |
| 160 |
// $cart_url = wc_get_cart_url(); |
| 161 |
|
| 162 |
// // Get checkout URL |
| 163 |
// $checkout_url = wc_get_checkout_url(); |
| 164 |
|
| 165 |
// $exclude_urls[] = esc_url($cart_url); |
| 166 |
// $exclude_urls[] = esc_url($checkout_url); |
| 167 |
|
| 168 |
// } |
| 169 |
|
| 170 |
// update_option('berq_exclude_urls', $exclude_urls); |
| 171 |
|
| 172 |
// } |
| 173 |
|
| 174 |
if (get_option('berqwp_enable_critical_css') === false) { |
| 175 |
update_option('berqwp_enable_critical_css', 1, false); |
| 176 |
} |
| 177 |
|
| 178 |
if (get_option('berqwp_enable_used_css') === false) { |
| 179 |
update_option('berqwp_enable_used_css', 0, false); |
| 180 |
} |
| 181 |
|
| 182 |
if (get_option('berqwp_force_include_critical_css') === false) { |
| 183 |
update_option('berqwp_force_include_critical_css', [], false); |
| 184 |
} |
| 185 |
|
| 186 |
if (!empty(get_option('berq_exclude_js_css'))) { |
| 187 |
$css_js_excludes = get_option('berq_exclude_js_css'); |
| 188 |
update_option('berqwp_exclude_css', $css_js_excludes, false); |
| 189 |
update_option('berqwp_exclude_js', $css_js_excludes, false); |
| 190 |
|
| 191 |
delete_option('berq_exclude_js_css'); |
| 192 |
} |
| 193 |
|
| 194 |
if (get_option('berqwp_exclude_css') === false) { |
| 195 |
update_option('berqwp_exclude_css', [], false); |
| 196 |
} |
| 197 |
|
| 198 |
if (get_option('berqwp_exclude_js') === false) { |
| 199 |
update_option('berqwp_exclude_js', [], false); |
| 200 |
} |
| 201 |
|
| 202 |
if (get_option('berqwp_exclude_third_party_js') === false) { |
| 203 |
update_option('berqwp_exclude_third_party_js', [], false); |
| 204 |
} |
| 205 |
|
| 206 |
if (get_option('berqwp_async_excluded_styles') === false) { |
| 207 |
update_option('berqwp_async_excluded_styles', 0, false); |
| 208 |
} |
| 209 |
|
| 210 |
if (get_option('berqwp_defer_excluded_styles') === false) { |
| 211 |
update_option('berqwp_defer_excluded_styles', 1, false); |
| 212 |
} |
| 213 |
|
| 214 |
if (get_option('berqwp_defer_excluded_js') === false) { |
| 215 |
update_option('berqwp_defer_excluded_js', 0, false); |
| 216 |
} |
| 217 |
|
| 218 |
if (get_option('berqwp_delay_third_party_scripts') === false) { |
| 219 |
update_option('berqwp_delay_third_party_scripts', 0, false); |
| 220 |
} |
| 221 |
|
| 222 |
if (get_option('berqwp_lazy_render') === false) { |
| 223 |
update_option('berqwp_lazy_render', 0, false); |
| 224 |
} |
| 225 |
|
| 226 |
if (get_option('berqwp_prerender_on_hover') === false) { |
| 227 |
update_option('berqwp_prerender_on_hover', 1, false); |
| 228 |
} |
| 229 |
|
| 230 |
if (get_option('berqwp_enable_webp') === false) { |
| 231 |
|
| 232 |
$bwp_enable_webp = 1; |
| 233 |
if (get_option('berqwp_disable_webp') !== false) { |
| 234 |
$bwp_enable_webp = !get_option('berqwp_disable_webp'); |
| 235 |
delete_option('berqwp_disable_webp'); |
| 236 |
} |
| 237 |
|
| 238 |
update_option('berqwp_enable_webp', (int) $bwp_enable_webp, false); |
| 239 |
} |
| 240 |
|
| 241 |
if (get_option('berqwp_exclude_lazy_load_images') === false) { |
| 242 |
update_option('berqwp_exclude_lazy_load_images', [], false); |
| 243 |
} |
| 244 |
|
| 245 |
if (get_option('berqwp_lazy_load_videos') === false) { |
| 246 |
update_option('berqwp_lazy_load_videos', 1, false); |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
if (get_option('berq_exclude_urls') === false) { |
| 251 |
$urls = get_option('berq_exclude_urls', []); |
| 252 |
|
| 253 |
if (class_exists('WooCommerce')) { |
| 254 |
$page_excludes = [ |
| 255 |
wc_get_cart_url(), |
| 256 |
wc_get_checkout_url(), |
| 257 |
trailingslashit(wc_get_cart_url()), |
| 258 |
trailingslashit(wc_get_checkout_url()), |
| 259 |
]; |
| 260 |
|
| 261 |
$page_excludes = array_unique($page_excludes); |
| 262 |
|
| 263 |
$page_excludes = array_filter($page_excludes, function ($url) use ($urls) { |
| 264 |
return !empty($url) && !in_array($url, $urls) && $url !== trailingslashit(home_url()); |
| 265 |
}); |
| 266 |
|
| 267 |
$should_update = !empty($page_excludes); |
| 268 |
$urls = array_merge($urls, $page_excludes); |
| 269 |
|
| 270 |
|
| 271 |
// if (!empty($cart_url) && !in_array($cart_url, $urls) && trailingslashit($cart_url) !== trailingslashit(home_url())) { |
| 272 |
// $urls[] = esc_url($cart_url); |
| 273 |
// $should_update = true; |
| 274 |
// } |
| 275 |
|
| 276 |
// if (!empty($checkout_url) && !in_array($checkout_url, $urls) && trailingslashit($checkout_url) !== trailingslashit(home_url())) { |
| 277 |
// $urls[] = esc_url($checkout_url); |
| 278 |
// $should_update = true; |
| 279 |
// } |
| 280 |
|
| 281 |
if ($should_update) { |
| 282 |
$berqconfigs->update_configs(['exclude_urls' => $urls]); |
| 283 |
update_option('berq_exclude_urls', $urls, false); |
| 284 |
|
| 285 |
} |
| 286 |
|
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
|
| 291 |
if (!empty(get_option('berqwp_optimize_queue'))) { |
| 292 |
delete_option('berqwp_optimize_queue'); |
| 293 |
} |