7
7
* @author Optimole <friends@optimole.com>
8
8
*/
9
9
final class Optml_Manager {
10
-
10
+ /**
11
+ * Holds allowed compatibilities objects.
12
+ *
13
+ * @var Optml_compatibility[] Compatibilities objects.
14
+ */
15
+ public static $ loaded_compatibilities = [];
11
16
/**
12
17
* Cached object instance.
13
18
*
14
19
* @var Optml_Manager
15
20
*/
16
21
protected static $ instance = null ;
17
-
18
22
/**
19
23
* Holds the url replacer class.
20
24
*
@@ -23,7 +27,6 @@ final class Optml_Manager {
23
27
* @var Optml_Url_Replacer Replacer instance.
24
28
*/
25
29
public $ url_replacer ;
26
-
27
30
/**
28
31
* Holds the tag replacer class.
29
32
*
@@ -32,7 +35,6 @@ final class Optml_Manager {
32
35
* @var Optml_Tag_Replacer Replacer instance.
33
36
*/
34
37
public $ tag_replacer ;
35
-
36
38
/**
37
39
* Holds the lazyload replacer class.
38
40
*
@@ -47,13 +49,12 @@ final class Optml_Manager {
47
49
* @var Optml_Settings WordPress settings.
48
50
*/
49
51
protected $ settings ;
50
-
51
52
/**
52
53
* Possible integrations with different plugins.
53
54
*
54
55
* @var array Integrations classes.
55
56
*/
56
- private $ compatibilities = array (
57
+ private $ possible_compatibilities = array (
57
58
'shortcode_ultimate ' ,
58
59
'foogallery ' ,
59
60
'envira ' ,
@@ -62,6 +63,7 @@ final class Optml_Manager {
62
63
'revslider ' ,
63
64
'metaslider ' ,
64
65
'woocommerce ' ,
66
+ 'yith_quick_view ' ,
65
67
);
66
68
67
69
/**
@@ -92,6 +94,20 @@ public function init() {
92
94
93
95
$ this ->settings = new Optml_Settings ();
94
96
97
+ foreach ( $ this ->possible_compatibilities as $ compatibility_class ) {
98
+ $ compatibility_class = 'Optml_ ' . $ compatibility_class ;
99
+ $ compatibility = new $ compatibility_class ;
100
+
101
+ /**
102
+ * Check if we should load compatibility.
103
+ *
104
+ * @var Optml_compatibility $compatibility Class to register.
105
+ */
106
+ if ( $ compatibility ->should_load () ) {
107
+ self ::$ loaded_compatibilities [ $ compatibility_class ] = $ compatibility ;
108
+ }
109
+ }
110
+
95
111
if ( ! $ this ->should_replace () ) {
96
112
return ;
97
113
}
@@ -112,7 +128,6 @@ public function should_replace() {
112
128
if ( ( is_admin () && ! self ::is_ajax_request () ) || ! $ this ->settings ->is_connected () || ! $ this ->settings ->is_enabled () || is_customize_preview () ) {
113
129
return false ; // @codeCoverageIgnore
114
130
}
115
-
116
131
if ( array_key_exists ( 'preview ' , $ _GET ) && 'true ' == $ _GET ['preview ' ] ) {
117
132
return false ; // @codeCoverageIgnore
118
133
}
@@ -140,7 +155,10 @@ public function should_replace() {
140
155
* @return bool Is ajax request?
141
156
*/
142
157
public static function is_ajax_request () {
158
+ if ( apply_filters ( 'optml_force_replacement_on ' , false ) === true ) {
143
159
160
+ return true ;
161
+ }
144
162
if ( ! function_exists ( 'is_user_logged_in ' ) ) {
145
163
return false ;
146
164
}
@@ -163,9 +181,7 @@ public static function is_ajax_request() {
163
181
* Register frontend replacer hooks.
164
182
*/
165
183
public function register_hooks () {
166
-
167
184
do_action ( 'optml_replacer_setup ' );
168
-
169
185
add_filter ( 'the_content ' , array ( $ this , 'process_images_from_content ' ), PHP_INT_MAX );
170
186
/**
171
187
* When we have to process cdn images, i.e MIRROR is defined,
@@ -180,23 +196,12 @@ public function register_hooks() {
180
196
),
181
197
defined ( 'OPTML_SITE_MIRROR ' ) ? PHP_INT_MAX : PHP_INT_MIN
182
198
);
183
-
184
199
add_action ( 'rest_api_init ' , array ( $ this , 'process_template_redirect_content ' ), PHP_INT_MIN );
185
200
186
201
add_action ( 'get_post_metadata ' , array ( $ this , 'replace_meta ' ), PHP_INT_MAX , 4 );
187
202
188
- foreach ( $ this ->compatibilities as $ compatibility_class ) {
189
- $ compatibility_class = 'Optml_ ' . $ compatibility_class ;
190
- $ compatibility = new $ compatibility_class ;
191
-
192
- /**
193
- * Check if we should load compatibility.
194
- *
195
- * @var Optml_compatibility $compatibility Class to register.
196
- */
197
- if ( $ compatibility ->should_load () ) {
198
- $ compatibility ->register ();
199
- }
203
+ foreach ( self ::$ loaded_compatibilities as $ registered_compatibility ) {
204
+ $ registered_compatibility ->register ();
200
205
}
201
206
}
202
207
@@ -324,6 +329,7 @@ function ( $url ) {
324
329
* @return mixed Filtered content.
325
330
*/
326
331
public function replace_content ( $ html ) {
332
+
327
333
$ html = $ this ->process_images_from_content ( $ html );
328
334
329
335
$ html = $ this ->process_urls_from_content ( $ html );
0 commit comments