@@ -44,13 +44,8 @@ function embed_optimizer_add_non_optimization_detective_hooks(): void {
44
44
* @param string $optimization_detective_version Current version of the optimization detective plugin.
45
45
*/
46
46
function embed_optimizer_init_optimization_detective ( string $ optimization_detective_version ): void {
47
- if (
48
- version_compare ( (string ) strtok ( $ optimization_detective_version , '- ' ), '1.0.0 ' , '< ' )
49
- ||
50
- '1.0.0-beta1 ' === $ optimization_detective_version
51
- ||
52
- '1.0.0-beta2 ' === $ optimization_detective_version
53
- ) {
47
+ $ required_od_version = '0.9.0 ' ;
48
+ if ( version_compare ( (string ) strtok ( $ optimization_detective_version , '- ' ), $ required_od_version , '< ' ) ) {
54
49
add_action (
55
50
'admin_notices ' ,
56
51
static function (): void {
@@ -192,6 +187,12 @@ function embed_optimizer_update_markup( WP_HTML_Tag_Processor $html_processor, b
192
187
$ trigger_error = static function ( string $ message ) use ( $ function_name ): void {
193
188
wp_trigger_error ( $ function_name , esc_html ( $ message ) );
194
189
};
190
+
191
+ // As of 1.0.0-beta3, next_tag() allows $query and is beginning to migrate to skip tag closers by default.
192
+ // In versions prior to this, the method always visited closers and passing a $query actually threw an exception.
193
+ $ tag_query = version_compare ( OPTIMIZATION_DETECTIVE_VERSION , '1.0.0-beta3 ' , '>= ' )
194
+ ? array ( 'tag_closers ' => 'visit ' )
195
+ : null ;
195
196
try {
196
197
/*
197
198
* Determine how to lazy load the embed.
@@ -258,7 +259,7 @@ function embed_optimizer_update_markup( WP_HTML_Tag_Processor $html_processor, b
258
259
}
259
260
}
260
261
}
261
- } while ( $ html_processor ->next_tag ( array ( ' tag_closers ' => ' visit ' ) ) );
262
+ } while ( $ html_processor ->next_tag ( $ tag_query ) );
262
263
// If there was only one non-inline script, make it lazy.
263
264
if ( 1 === $ script_count && ! $ has_inline_script && $ html_processor ->has_bookmark ( $ bookmark_names ['script ' ] ) ) {
264
265
$ needs_lazy_script = true ;
0 commit comments