PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / trunk
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript vtrunk
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 1.9.7 All 169 releases
searchpro / inc / initialize.php

initialize.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript trunk, at inc/initialize.php

309 lines 9.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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', 5, 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 if (get_option('berqwp_heartbeat_mode') === false) {
130 update_option('berqwp_heartbeat_mode', 'default', false);
131 }
132
133 if (get_option('berqwp_db_schedule_frequency') === false) {
134 update_option('berqwp_db_schedule_frequency', 'weekly', false);
135 }
136
137 if (get_option('berqwp_db_revision_limit') === false) {
138 update_option('berqwp_db_revision_limit', 5, false);
139 }
140
141 if (get_option('berqwp_db_scheduled_tasks') === false) {
142 update_option('berqwp_db_scheduled_tasks', ['revisions', 'transients', 'spam_comments'], false);
143 }
144
145
146
147 if (get_option('berq_exclude_cdn') === false) {
148 update_option('berq_exclude_cdn', [], false);
149 }
150
151 if (get_option('berqwp_optimize_taxonomies') === false) {
152 update_option('berqwp_optimize_taxonomies', ['category', 'product_cat'], false);
153 }
154
155 if (get_option('berq_ignore_urls_params') === false) {
156 update_option('berq_ignore_urls_params', ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'fbclid', 'msclkid'], false);
157 }
158
159 // if (empty($berqwp_configs['site_id'])) {
160 // $blog_id = get_current_blog_id();
161 // $network_id = function_exists('get_current_network_id') ? get_current_network_id() : 1;
162 // $siteurl = get_option('siteurl');
163 // $site_id = md5("berqwp|$network_id|$blog_id|$siteurl");
164
165 // $berqconfigs->update_configs(['site_id' => $site_id]);
166 // }
167
168
169 // if (get_option('berq_exclude_urls', null) == null) {
170 // $exclude_urls = [];
171
172 // if (class_exists('WooCommerce')) {
173 // // WooCommerce is active
174
175 // // Get cart URL
176 // $cart_url = wc_get_cart_url();
177
178 // // Get checkout URL
179 // $checkout_url = wc_get_checkout_url();
180
181 // $exclude_urls[] = esc_url($cart_url);
182 // $exclude_urls[] = esc_url($checkout_url);
183
184 // }
185
186 // update_option('berq_exclude_urls', $exclude_urls);
187
188 // }
189
190 if (get_option('berqwp_enable_critical_css') === false) {
191 update_option('berqwp_enable_critical_css', 1, false);
192 }
193
194 if (get_option('berqwp_enable_used_css') === false) {
195 update_option('berqwp_enable_used_css', 0, false);
196 }
197
198 if (get_option('berqwp_force_include_critical_css') === false) {
199 update_option('berqwp_force_include_critical_css', [], false);
200 }
201
202 if (!empty(get_option('berq_exclude_js_css'))) {
203 $css_js_excludes = get_option('berq_exclude_js_css');
204 update_option('berqwp_exclude_css', $css_js_excludes, false);
205 update_option('berqwp_exclude_js', $css_js_excludes, false);
206
207 delete_option('berq_exclude_js_css');
208 }
209
210 if (get_option('berqwp_exclude_css') === false) {
211 update_option('berqwp_exclude_css', [], false);
212 }
213
214 if (get_option('berqwp_exclude_js') === false) {
215 update_option('berqwp_exclude_js', [], false);
216 }
217
218 if (get_option('berqwp_exclude_third_party_js') === false) {
219 update_option('berqwp_exclude_third_party_js', [], false);
220 }
221
222 if (get_option('berqwp_async_excluded_styles') === false) {
223 update_option('berqwp_async_excluded_styles', 0, false);
224 }
225
226 if (get_option('berqwp_defer_excluded_styles') === false) {
227 update_option('berqwp_defer_excluded_styles', 1, false);
228 }
229
230 if (get_option('berqwp_defer_excluded_js') === false) {
231 update_option('berqwp_defer_excluded_js', 0, false);
232 }
233
234 if (get_option('berqwp_delay_third_party_scripts') === false) {
235 update_option('berqwp_delay_third_party_scripts', 0, false);
236 }
237
238 if (get_option('berqwp_lazy_render') === false) {
239 update_option('berqwp_lazy_render', 0, false);
240 }
241
242 if (get_option('berqwp_prerender_on_hover') === false) {
243 update_option('berqwp_prerender_on_hover', 1, false);
244 }
245
246 if (get_option('berqwp_enable_webp') === false) {
247
248 $bwp_enable_webp = 1;
249 if (get_option('berqwp_disable_webp') !== false) {
250 $bwp_enable_webp = !get_option('berqwp_disable_webp');
251 delete_option('berqwp_disable_webp');
252 }
253
254 update_option('berqwp_enable_webp', (int) $bwp_enable_webp, false);
255 }
256
257 if (get_option('berqwp_exclude_lazy_load_images') === false) {
258 update_option('berqwp_exclude_lazy_load_images', [], false);
259 }
260
261 if (get_option('berqwp_lazy_load_videos') === false) {
262 update_option('berqwp_lazy_load_videos', 1, false);
263 }
264
265
266 if (get_option('berq_exclude_urls') === false) {
267 $urls = get_option('berq_exclude_urls', []);
268
269 if (class_exists('WooCommerce')) {
270 $page_excludes = [
271 wc_get_cart_url(),
272 wc_get_checkout_url(),
273 trailingslashit(wc_get_cart_url()),
274 trailingslashit(wc_get_checkout_url()),
275 ];
276
277 $page_excludes = array_unique($page_excludes);
278
279 $page_excludes = array_filter($page_excludes, function ($url) use ($urls) {
280 return !empty($url) && !in_array($url, $urls) && $url !== trailingslashit(home_url());
281 });
282
283 $should_update = !empty($page_excludes);
284 $urls = array_merge($urls, $page_excludes);
285
286
287 // if (!empty($cart_url) && !in_array($cart_url, $urls) && trailingslashit($cart_url) !== trailingslashit(home_url())) {
288 // $urls[] = esc_url($cart_url);
289 // $should_update = true;
290 // }
291
292 // if (!empty($checkout_url) && !in_array($checkout_url, $urls) && trailingslashit($checkout_url) !== trailingslashit(home_url())) {
293 // $urls[] = esc_url($checkout_url);
294 // $should_update = true;
295 // }
296
297 if ($should_update) {
298 $berqconfigs->update_configs(['exclude_urls' => $urls]);
299 update_option('berq_exclude_urls', $urls, false);
300
301 }
302
303 }
304 }
305
306
307 if (!empty(get_option('berqwp_optimize_queue'))) {
308 delete_option('berqwp_optimize_queue');
309 }