PluginProbe ʕ •ᴥ•ʔ
10Web Booster – Website speed optimization, Cache & Page Speed optimizer / trunk
10Web Booster – Website speed optimization, Cache & Page Speed optimizer vtrunk
2.33.0 2.30.5 2.30.7 2.30.9 2.31.10 2.31.8 2.32.11 2.32.21 2.32.3 2.32.4 2.32.7 2.6.31 2.6.40 2.6.42 2.6.7 2.7.37 2.7.44 2.7.47 2.8.18 2.8.19 2.8.32 2.8.34 2.8.35 2.9.23 2.9.24 2.9.25 2.9.27 v2.27.4 trunk 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.17 2.0.18 2.0.21 2.0.22 2.0.25 2.0.26 2.0.27 2.0.3 2.0.7 2.0.9 2.10.46 2.10.65 2.10.66 2.10.68 2.11.41 2.11.42 2.11.43 2.12.15 2.12.21 2.12.22 2.12.23 2.12.26 2.13.37 2.13.40 2.13.41 2.13.42 2.13.44 2.13.45 2.13.47 2.14.49 2.14.50 2.15.18 2.17.21 2.17.23 2.18.17 2.19.44 2.19.45 2.19.46 2.19.49 2.2.12 2.2.15 2.2.16 2.2.18 2.2.8 2.20.31 2.20.32 2.20.33 2.21.11 2.21.12 2.21.16 2.21.25 2.22.32 2.23.13 2.23.15 2.23.16 2.23.18 2.24.12 2.24.14 2.24.18 2.25.14 2.26.6 2.28.10 2.28.13 2.28.14 2.28.7 2.29.1 2.29.2 2.29.3 2.3.0 2.3.1 2.3.2 2.3.3 2.30.18
tenweb-speed-optimizer / tenweb_speed_optimizer.php
tenweb-speed-optimizer Last commit date
assets 11 months ago config 2 years ago exported 4 years ago includes 2 months ago test 4 years ago vendor 1 month ago views 11 months ago .editorconfig 3 years ago OptimizerAdmin.php 1 year ago OptimizerAdminBar.php 2 years ago OptimizerApi.php 1 month ago OptimizerCli.php 1 year ago OptimizerDataRepository.php 1 year ago changelog.txt 3 years ago config.php 1 month ago env.php 1 month ago phpcs.xml 3 years ago readme.txt 1 month ago tenweb_speed_optimizer.php 1 month ago webpack.config.js 3 years ago
tenweb_speed_optimizer.php
438 lines
1 <?php
2
3 /**
4 * Plugin Name: 10Web Booster
5 * Plugin URI: https://10web.io/page-speed-booster/
6 * Description: Optimize your website speed and performance with 10Web Booster by compressing CSS and JavaScript.
7 * Version: 2.33.0
8 * Author: 10Web - Website speed optimization team
9 * Author URI: https://10web.io/
10 * Text Domain: tenweb-speed-optimizer
11 */
12
13 use TenWebOptimizer\OptimizerOnInit;
14 use TenWebOptimizer\OptimizerScripts;
15 use TenWebOptimizer\OptimizerUtils;
16 use TenWebOptimizer\OptimizerWhiteLabel;
17
18 if (!defined('ABSPATH')) {
19 exit;
20 }
21
22 if (!defined('TWO_ALWAYS_CRITICAL')) {
23 define('TWO_ALWAYS_CRITICAL', true);
24 }
25
26 if (!defined('TWO_PLUGIN_FILE')) {
27 define('TWO_PLUGIN_FILE', __FILE__);
28 }
29
30 if (isset($_GET['two_check_redirect']) && $_GET['two_check_redirect'] === '1') { // phpcs:ignore
31 return;
32 }
33
34 $two_skip_until = get_option('two_skip_loading_and_working');
35
36 if ($two_skip_until && strtotime($two_skip_until . ' UTC') > time()) {
37 return;
38 }
39
40 global $two_incompatible_errors;
41 $two_incompatible_errors = [];
42 require_once __DIR__ . '/config.php';
43
44 if (PHP_MAJOR_VERSION < 7 || (PHP_MAJOR_VERSION === 7 && PHP_MINOR_VERSION <= 3)) {
45 if (!defined('TWO_INCOMPATIBLE_ERROR')) {
46 define('TWO_INCOMPATIBLE_ERROR', true);
47 }
48 $two_incompatible_errors[] = [ 'title' => __('PHP compatibility error:', 'tenweb-speed-optimizer'),
49 'message' => __('PHP 7.4 or a newer version is required for 10Web Booster. Please update your PHP version to proceed.', 'tenweb-speed-optimizer') ];
50 }
51
52 if (!in_array('dom', get_loaded_extensions())) {
53 if (!defined('TWO_INCOMPATIBLE_ERROR')) {
54 define('TWO_INCOMPATIBLE_ERROR', true);
55 }
56 $two_incompatible_errors[] = [ 'title' => __('Class \'DOMDocument\' is not found in PHP:', 'tenweb-speed-optimizer'),
57 'message' => __('PHP \'DOMDocument\' extension is required for 10Web Booster. Please install PHP \'DOMDocument\' extension to proceed.', 'tenweb-speed-optimizer') ];
58 }
59
60 if (get_site_transient('tenweb_so_auth_error_logs')) {
61 if (!defined('TWO_INCOMPATIBLE_WARNING')) {
62 define('TWO_INCOMPATIBLE_WARNING', true);
63 }
64 $two_incompatible_errors[] = [ 'title' => __('Trouble connecting your website to 10Web:', 'tenweb-speed-optimizer'),
65 'message' => __(get_site_transient('tenweb_so_auth_error_logs'), 'tenweb-speed-optimizer') ];
66 delete_site_transient('tenweb_so_auth_error_logs');
67 }
68
69 if (is_multisite() && !TENWEB_SO_HOSTED_ON_10WEB) {
70 if (!defined('TWO_HOSTED_MULTISITE')) {
71 define('TWO_HOSTED_MULTISITE', true);
72 }
73
74 if (!defined('TWO_INCOMPATIBLE_ERROR')) {
75 define('TWO_INCOMPATIBLE_ERROR', true);
76 }
77 $two_incompatible_errors[] = [ 'title' => __('Multisite not supported:', 'tenweb-speed-optimizer'),
78 'message' => __('This feature will be available soon.', 'tenweb-speed-optimizer') ];
79 }
80
81 if (defined('TWO_INCOMPATIBLE_ERROR') && TWO_INCOMPATIBLE_ERROR) {
82 if (is_plugin_active('airlift/airlift.php')) {
83 two_incompatible_admin_requirements();
84 add_action('wp_ajax_two_deactivate_plugins', [ '\TenWebOptimizer\OptimizerAdmin', 'two_deactivate_plugin' ]);
85 }
86 add_action('admin_menu', function () {
87 two_incompatible_admin_requirements();
88 two_define_so_organization_name();
89 add_menu_page(
90 TWO_SO_ORGANIZATION_NAME . ' Booster',
91 TWO_SO_ORGANIZATION_NAME . ' Booster',
92 'manage_options',
93 'two_settings_page',
94 [
95 '\TenWebOptimizer\OptimizerAdmin',
96 'settings_page',
97 ],
98 TENWEB_SO_URL . '/assets/images/speed/logo.svg',
99 10
100 );
101 });
102 add_action('admin_enqueue_scripts', [ '\TenWebOptimizer\OptimizerAdmin', 'two_enqueue_admin_assets' ]);
103 } else {
104 include_files();
105 two_define_so_organization_name();
106
107 \TenWebOptimizer\OptimizerLogger::get_instance();
108
109 global $tenweb_subscription_id;
110 global $tenweb_plan_title;
111 $tenweb_plan_title = \TenWebWpTransients\OptimizerTransients::get(TENWEB_PREFIX . '_plan_title');
112 $tenweb_subscription_id = \TenWebWpTransients\OptimizerTransients::get(TENWEB_PREFIX . '_subscription_id');
113 $tenweb_subscription_response_code = \TenWebWpTransients\OptimizerTransients::get(TENWEB_PREFIX . '_subscription_response_code');
114
115 if (empty($tenweb_subscription_id) && $tenweb_subscription_id !== '0' && ((string) $tenweb_subscription_response_code === '200' || $tenweb_subscription_response_code === false)) {
116 $tenweb_subscription_array = \TenWebOptimizer\OptimizerUtils::two_update_subscription();
117
118 if ($tenweb_subscription_array['tenweb_subscription_id'] !== false) {
119 $tenweb_subscription_id = $tenweb_subscription_array['tenweb_subscription_id'];
120 $tenweb_plan_title = strtolower($tenweb_subscription_array['tenweb_plan_title']) == 'speed' ? 'Free' : $tenweb_plan_title; //sometimes we get 'speed' from service, it means free
121 } else {
122 $tenweb_subscription_id = TENWEB_SO_FREE_SUBSCRIPTION_ID;
123 $tenweb_plan_title = 'Free';
124 }
125 } elseif ($tenweb_subscription_id == '0' && !TENWEB_SO_HOSTED_ON_10WEB) {
126 $tenweb_subscription_id = TENWEB_SO_FREE_SUBSCRIPTION_ID;
127 $tenweb_plan_title = 'Free';
128 }
129
130 new OptimizerOnInit();
131 register_deactivation_hook(__FILE__, ['\TenWebOptimizer\OptimizerAdmin', 'two_deactivate']);
132 register_uninstall_hook(__FILE__, ['\TenWebOptimizer\OptimizerAdmin', 'two_uninstall']);
133
134 global $TwoSettings;
135 $TwoSettings = \TenWebOptimizer\OptimizerSettings::get_instance();
136
137 OptimizerOnInit::maybe_update_excluded_css_list();
138
139 if (!isset($_GET['action']) || $_GET['action'] != 'deactivate') { // phpcs:ignore
140 register_activation_hook(__FILE__, ['\TenWebOptimizer\OptimizerAdmin', 'two_activate']);
141 add_action('plugins_loaded', 'two_init');
142 }
143 }
144
145 function two_incompatible_admin_requirements()
146 {
147 require_once TENWEB_SO_PLUGIN_DIR . '/includes/OptimizerOnInit.php';
148 require_once TENWEB_SO_PLUGIN_DIR . 'OptimizerAdmin.php';
149 require_once TENWEB_SO_PLUGIN_DIR . '/includes/OptimizerUtils.php';
150 require_once TENWEB_SO_PLUGIN_DIR . '/includes/OptimizerWhiteLabel.php';
151 }
152
153 if (defined('TWO_SO_COMPANY_NAME') && get_option('two_so_organization_name') === false) {
154 update_option('two_so_organization_name', TWO_SO_COMPANY_NAME);
155 }
156
157 function include_files()
158 {
159 require_once __DIR__ . '/vendor/autoload.php';
160 }
161
162 function add_attr_to_script($tag, $handle)
163 {
164 if ($handle === 'two_preview_js' || $handle === 'jquery-core') {
165 return str_replace('<script', '<script ' . esc_attr(OptimizerScripts::TWO_DISABLE_PAGESPEED_DEFER_ATTRIBUTE) . ' ' . esc_attr(OptimizerScripts::TWO_NO_DELAYED_JS_ATTRIBUTE) . ' ', $tag);
166 }
167
168 return $tag;
169 }
170
171 if (isset($_GET['two_preview']) && $_GET['two_preview'] === '1') { // phpcs:ignore
172 add_filter('determine_current_user', function ($user_id) {
173 if ($user_id) {
174 return 0;
175 }
176
177 return $user_id;
178 }, 99);
179 }
180
181 function two_init()
182 {
183 if (isset($_GET['two_setup']) && $_GET['two_setup'] === '1') { // phpcs:ignore
184 if (is_user_logged_in()) {
185 two_init_preview();
186 } else {
187 $two_preview_url = add_query_arg(['two_setup' => '1'], get_home_url() . '/');
188 $two_preview_url = urlencode($two_preview_url);
189 $two_preview_login_url = add_query_arg([ 'redirect_to' => $two_preview_url], wp_login_url());
190 OptimizerUtils::two_redirect($two_preview_login_url);
191 }
192 $two_conflicting_plugins = OptimizerUtils::get_conflicting_plugins();
193 $two_triggerPostOptimizationTasks = get_option('two_triggerPostOptimizationTasks');
194
195 if (empty($two_conflicting_plugins)) {
196 $two_conflicting_plugins = [];
197 }
198 $incompatible_plugins_active_send = get_option('incompatible_plugins_active_send');
199
200 if ($two_triggerPostOptimizationTasks !== '1' && $incompatible_plugins_active_send !== '1') {
201 update_option('incompatible_plugins_active_send', '1');
202 OptimizerUtils::update_connection_flow_progress('running', 'incompatible_plugins_active', array_values($two_conflicting_plugins));
203 }
204 }
205
206 if (isset($_GET['two_preview']) && $_GET['two_preview'] === '1') { // phpcs:ignore
207 if (isset($_GET['two_level'])) { // phpcs:ignore
208 add_filter('option_active_plugins', function ($plugins) {
209 $two_plugin_filter_data = OptimizerUtils::filter_incompatible_plugins($plugins);
210
211 if (isset($two_plugin_filter_data['compatible'])) {
212 return $two_plugin_filter_data['compatible'];
213 }
214
215 return $plugins;
216 });
217 }
218 }
219
220 add_filter('wcml_user_store_strategy', function () {
221 // wcml_client_currency should be kept in cookies (not in session), otherwise page cache will not work
222 return 'cookie';
223 });
224
225 add_action('wp_ajax_two_set_critical', 'two_set_critical');
226 add_action('wp_ajax_nopriv_two_set_critical', 'two_set_critical');
227
228 add_action('wp_ajax_two_init_flow_score', 'two_init_flow_score');
229 add_action('wp_ajax_nopriv_two_init_flow_score', 'two_init_flow_score');
230
231 add_action('wp_ajax_two_activate_score_check', 'two_activate_score_check');
232 add_action('wp_ajax_nopriv_two_activate_score_check', 'two_activate_score_check');
233
234 add_action('wp_ajax_two_optimize_page', 'two_optimize_page');
235
236 require __DIR__ . '/OptimizerApi.php';
237 $OptimizerApi = new \TenWebOptimizer\OptimizerApi();
238
239 \TenWebIO\PreInit::check('booster');
240 \TenWebWpBenchmark\Init::getInstance();
241
242 global $TwoSettings;
243
244 if (defined('WP_CLI') && WP_CLI) { //Run only TWO CLI in WP_CLI mode
245 require __DIR__ . '/OptimizerCli.php';
246
247 return;
248 }
249
250 $two_disable_jetpack_optimization = $TwoSettings->get_settings('two_disable_jetpack_optimization');
251
252 if ('on' === $two_disable_jetpack_optimization) {
253 add_filter('option_jetpack_active_modules', 'two_jetpack_module_override');
254 function two_jetpack_module_override($modules)
255 {
256 $disabled_modules = [
257 'lazy-images',
258 'photon',
259 'photon-cdn',
260 ];
261
262 foreach ($disabled_modules as $module_slug) {
263 $found = array_search($module_slug, $modules);
264
265 if (false !== $found) {
266 unset($modules[ $found ]);
267 }
268 }
269
270 return $modules;
271 }
272 }
273 \TenWebOptimizer\OptimizerAdmin::get_instance();
274 $global_mode = get_option('two_default_mode', OptimizerUtils::MODES['extreme']);
275 $global_mode_name = '';
276
277 if (is_array($global_mode)) {
278 $global_mode_name = $global_mode['mode'];
279 }
280
281 if (\Tenweb_Authorization\Login::get_instance()->check_logged_in()) {
282 if ($global_mode_name !== 'no_optimize' &&
283 (empty(\TenWebOptimizer\OptimizerUtils::IOConnected()) || !empty(\TenWebOptimizer\OptimizerUtils::TWOConnected()))) {
284 \TenWebOptimizer\OptimizerMain::get_instance();
285 \TenWebOptimizer\WebPageCache\OptimizerWebPageCacheWP::get_instance();
286 }
287 } else {
288 do_action('two_main_authorization_failed');
289 }
290
291 if (isset($_GET['two_action']) && $_GET['two_action'] === 'generating_critical_css') { // phpcs:ignore
292 ob_start('two_critical', 0, PHP_OUTPUT_HANDLER_REMOVABLE);
293 }
294 }
295
296 function two_init_flow_score()
297 {
298 if (isset($_POST['nonce'])) { // phpcs:ignore
299 $p_nonce = sanitize_text_field($_POST['nonce']); // phpcs:ignore
300 $nonce = get_option('wp_two_nonce_two_init_flow_score');
301 delete_option('wp_two_nonce_two_init_flow_score');
302
303 if ($p_nonce === $nonce && OptimizerUtils::check_admin_capabilities()) {
304 OptimizerUtils::init_flow_score_check();
305 }
306 }
307 }
308 function two_activate_score_check()
309 {
310 if (isset($_POST['nonce'])) { // phpcs:ignore
311 $p_nonce = sanitize_text_field($_POST['nonce']); // phpcs:ignore
312 $nonce = get_option('two_activate_score_check_nonce_data');
313 delete_option('two_activate_score_check_nonce_data');
314
315 if ($p_nonce === $nonce) {
316 // Check already optimized pages scores before and after optimize.
317 $optimized_pages = array_keys(\TenWebOptimizer\OptimizerUtils::getCriticalPages());
318
319 foreach ($optimized_pages as $optimizedPageID) {
320 if ($optimizedPageID != 'front_page') {
321 \TenWebSC\TWScoreChecker::twsc_check_score($optimizedPageID, true, true); /* Not optimized.*/
322 \TenWebSC\TWScoreChecker::twsc_check_score($optimizedPageID); /* Optimized.*/
323 }
324 }
325 }
326 }
327 }
328
329 function two_init_preview()
330 {
331 $two_flow_mode_select = get_site_option('two_flow_mode_select');
332
333 if ($two_flow_mode_select !== '1') {
334 update_site_option('two_flow_mode_select', '1');
335 OptimizerUtils::update_connection_flow_progress('running', 'mode_selection');
336 }
337 add_action('wp_enqueue_scripts', 'two_preview_assets');
338 }
339
340 function two_preview_assets()
341 {
342 $flow_id = get_site_option(TENWEB_PREFIX . '_flow_id');
343
344 $two_conflicting_plugins = OptimizerUtils::get_conflicting_plugins();
345 $two_first_optimization = get_option('two_first_optimization');
346 wp_enqueue_style('two_google-fonts', 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&display=swap', [], TENWEB_SO_VERSION);
347 wp_enqueue_script('two_preview_js', TENWEB_SO_URL . '/assets/js/two_preview.js', ['jquery'], TENWEB_SO_VERSION);
348 wp_enqueue_style('two_preview_css', TENWEB_SO_URL . '/assets/css/two_preview.css', [], TENWEB_SO_VERSION);
349 $two_preview_localize_data = [
350 'global_mode' => '',
351 'two_first_optimization' => $two_first_optimization,
352 'home_url' => get_home_url() . '/',
353 'flow_id' => $flow_id,
354 'skip_url' => TENWEB_DASHBOARD . '?flow_skip=1&optimizing_website=' . get_site_option(TENWEB_PREFIX . '_domain_id'),
355 'contact_us_url' => TENWEB_DASHBOARD . '?flow_contact_us=1&optimizing_website=' . get_site_option(TENWEB_PREFIX . '_domain_id') . '&open=livechat',
356 'success_url' => TENWEB_DASHBOARD . '?flow_success=1&optimizing_website=' . get_site_option(TENWEB_PREFIX . '_domain_id'),
357 'two_modes' => json_encode(\TenWebOptimizer\OptimizerUtils::get_modes(null, true)), // phpcs:ignore
358 'no_delay' => esc_attr(OptimizerScripts::TWO_DISABLE_PAGESPEED_DEFER_ATTRIBUTE) . ' ' . esc_attr(OptimizerScripts::TWO_NO_DELAYED_JS_ATTRIBUTE),
359 'incompatible_plugins' => false,
360 'ajaxurl' => admin_url('admin-ajax.php'),
361 'ajaxnonce' => wp_create_nonce('two_ajax_nonce'),
362 'two_company_name' => TWO_SO_ORGANIZATION_NAME,
363 ];
364 $two_default_mode = get_option('two_default_mode', OptimizerUtils::MODES['extreme']);
365
366 if (isset($two_default_mode) && is_array($two_default_mode)) {
367 $two_preview_localize_data['global_mode'] = $two_default_mode['mode'];
368 }
369
370 if (is_array($two_conflicting_plugins) && !empty($two_conflicting_plugins)) {
371 update_site_option('two_conflicting_plugins', $two_conflicting_plugins);
372 $two_preview_localize_data['incompatible_plugins'] = json_encode($two_conflicting_plugins); // phpcs:ignore
373 }
374 wp_localize_script('two_preview_js', 'two_preview_vars', $two_preview_localize_data);
375 add_filter('script_loader_tag', 'add_attr_to_script', 10, 3);
376 }
377
378 function two_critical($content)
379 {
380 return \TenWebOptimizer\OptimizerUtils::clear_iframe_src($content);
381 }
382
383 function two_set_critical()
384 {
385 \TenWebOptimizer\OptimizerUtils::set_critical();
386 }
387
388 /**
389 * Optimize the given page.
390 *
391 * @param $check_score
392 *
393 * @return void
394 */
395 function two_optimize_page()
396 {
397 $nonce = isset($_GET['nonce']) ? sanitize_text_field($_GET['nonce']) : '';
398
399 if (!wp_verify_nonce($nonce, 'two_ajax_nonce') || !OptimizerUtils::check_admin_capabilities()) {
400 die('Permission Denied.');
401 }
402
403 $post_id = isset($_GET['post_id']) ? intval($_GET['post_id']) : 0;
404
405 if (!$post_id) {
406 return;
407 }
408
409 \TenWebWpTransients\OptimizerTransients::set('two_optimize_inprogress_' . $post_id, '1', 30 * MINUTE_IN_SECONDS);
410 // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
411 //two_update_score_info($post_id, $page_score);
412 $initiator = isset($_GET['initiator']) ? sanitize_text_field($_GET['initiator']) : '';
413 /* Keeping all posts statuses which is in progress or optimized to manage notif popup view one time for each case */
414 $two_optimization_notif_status = get_option('two_optimization_notif_status');
415 $two_optimization_notif_status[$post_id] = 'optimizing';
416 update_option('two_optimization_notif_status', $two_optimization_notif_status, 1);
417
418 // Get and score in DB the page speed score before optimize.
419 \TenWebSC\TWScoreChecker::twsc_check_score($post_id, true, true);
420 \TenWebOptimizer\OptimizerCriticalCss::generate_critical_css_by_id($post_id, false, $initiator);
421
422 die;
423 }
424
425 function two_define_so_organization_name()
426 {
427 if (get_option('two_so_organization_name') && get_option('two_so_organization_name') != '') {
428 $organization_name = get_option('two_so_organization_name');
429 define('TWO_SO_ORGANIZATION_NAME', $organization_name);
430 $whiteLabel = OptimizerWhiteLabel::get_instance();
431 $whiteLabel->register_hooks();
432 } elseif (class_exists('\Tenweb_Manager\Helper') && method_exists('\Tenweb_Manager\Helper', 'get_company_name') && strtolower(\Tenweb_Manager\Helper::get_company_name()) !== '10web') {
433 define('TWO_SO_ORGANIZATION_NAME', \Tenweb_Manager\Helper::get_company_name());
434 } else {
435 define('TWO_SO_ORGANIZATION_NAME', '10Web');
436 }
437 }
438