PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.6.21
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.6.21
2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 2.6.4 2.6.3 2.5.23 All 138 releases
metasync / code-minification / class-compatibility-guard.php

class-compatibility-guard.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.6.21, at code-minification/class-compatibility-guard.php

150 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Metasync_Compatibility_Guard
4 * Detects conflicting minification/optimization features in other plugins
5 * to prevent double-processing and conflicts.
6 *
7 * @package Search Atlas SEO
8 * @copyright Copyright (C) 2021-2025, Search Atlas Group - support@searchatlas.com
9 * @since 2.5.23
10 */
11
12 if (!defined('ABSPATH')) {
13 exit;
14 }
15
16 class Metasync_Compatibility_Guard {
17
18 /**
19 * Check if CSS minification should be skipped due to another plugin.
20 *
21 * @return string|false Name of conflicting plugin, or false if no conflict.
22 */
23 public static function should_skip_css_minify() {
24 // WP Rocket
25 if (function_exists('get_rocket_option') && get_rocket_option('minify_css')) {
26 return 'WP Rocket';
27 }
28
29 // LiteSpeed Cache
30 if (defined('LSCWP_V') && self::get_litespeed_option('css_minify')) {
31 return 'LiteSpeed Cache';
32 }
33
34 // Autoptimize
35 if (class_exists('autoptimizeCache') && get_option('autoptimize_css') === 'on') {
36 return 'Autoptimize';
37 }
38
39 // W3 Total Cache
40 if (function_exists('w3tc_minify_flush')) {
41 return 'W3 Total Cache';
42 }
43
44 // SG Optimizer
45 if (class_exists('SiteGround_Optimizer\\Options\\Options')) {
46 if (\SiteGround_Optimizer\Options\Options::is_enabled('siteground_optimizer_combine_css')) {
47 return 'SG Optimizer';
48 }
49 }
50
51 return false;
52 }
53
54 /**
55 * Check if JS minification should be skipped due to another plugin.
56 *
57 * @return string|false Name of conflicting plugin, or false if no conflict.
58 */
59 public static function should_skip_js_minify() {
60 // WP Rocket
61 if (function_exists('get_rocket_option') && get_rocket_option('minify_js')) {
62 return 'WP Rocket';
63 }
64
65 // LiteSpeed Cache
66 if (defined('LSCWP_V') && self::get_litespeed_option('js_minify')) {
67 return 'LiteSpeed Cache';
68 }
69
70 // Autoptimize
71 if (class_exists('autoptimizeCache') && get_option('autoptimize_js') === 'on') {
72 return 'Autoptimize';
73 }
74
75 // W3 Total Cache
76 if (function_exists('w3tc_minify_flush')) {
77 return 'W3 Total Cache';
78 }
79
80 // SG Optimizer
81 if (class_exists('SiteGround_Optimizer\\Options\\Options')) {
82 if (\SiteGround_Optimizer\Options\Options::is_enabled('siteground_optimizer_combine_javascript')) {
83 return 'SG Optimizer';
84 }
85 }
86
87 return false;
88 }
89
90 /**
91 * Check if JS defer should be skipped.
92 *
93 * @return string|false Name of conflicting plugin, or false if no conflict.
94 */
95 public static function should_skip_js_defer() {
96 // WP Rocket
97 if (function_exists('get_rocket_option') && get_rocket_option('defer_all_js')) {
98 return 'WP Rocket';
99 }
100
101 // LiteSpeed Cache
102 if (defined('LSCWP_V') && self::get_litespeed_option('optm-js_defer')) {
103 return 'LiteSpeed Cache';
104 }
105
106 return false;
107 }
108
109 /**
110 * Get all active conflicts for display in admin UI.
111 *
112 * @return array ['css_minify' => 'Plugin Name', 'js_minify' => 'Plugin Name', ...]
113 */
114 public static function get_active_conflicts(): array {
115 $conflicts = [];
116
117 $css_conflict = self::should_skip_css_minify();
118 if ($css_conflict) {
119 $conflicts['css_minify'] = $css_conflict;
120 }
121
122 $js_conflict = self::should_skip_js_minify();
123 if ($js_conflict) {
124 $conflicts['js_minify'] = $js_conflict;
125 }
126
127 $defer_conflict = self::should_skip_js_defer();
128 if ($defer_conflict) {
129 $conflicts['js_defer'] = $defer_conflict;
130 }
131
132 return $conflicts;
133 }
134
135 /**
136 * Helper to get LiteSpeed Cache option.
137 *
138 * @param string $key Option key without prefix.
139 * @return bool
140 */
141 private static function get_litespeed_option(string $key): bool {
142 if (!defined('LSCWP_V')) {
143 return false;
144 }
145
146 $conf = get_option('litespeed.conf.' . $key);
147 return !empty($conf);
148 }
149 }
150