Skip to content

Commit b45e4bb

Browse files
Opt to vary query arg for next_tag() by OD version
Co-authored-by: felixarntz <[email protected]>
1 parent 6e9bb16 commit b45e4bb

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

plugins/embed-optimizer/hooks.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,8 @@ function embed_optimizer_add_non_optimization_detective_hooks(): void {
4444
* @param string $optimization_detective_version Current version of the optimization detective plugin.
4545
*/
4646
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, '<' ) ) {
5449
add_action(
5550
'admin_notices',
5651
static function (): void {
@@ -192,6 +187,12 @@ function embed_optimizer_update_markup( WP_HTML_Tag_Processor $html_processor, b
192187
$trigger_error = static function ( string $message ) use ( $function_name ): void {
193188
wp_trigger_error( $function_name, esc_html( $message ) );
194189
};
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;
195196
try {
196197
/*
197198
* Determine how to lazy load the embed.
@@ -258,7 +259,7 @@ function embed_optimizer_update_markup( WP_HTML_Tag_Processor $html_processor, b
258259
}
259260
}
260261
}
261-
} while ( $html_processor->next_tag( array( 'tag_closers' => 'visit' ) ) );
262+
} while ( $html_processor->next_tag( $tag_query ) );
262263
// If there was only one non-inline script, make it lazy.
263264
if ( 1 === $script_count && ! $has_inline_script && $html_processor->has_bookmark( $bookmark_names['script'] ) ) {
264265
$needs_lazy_script = true;

plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ private function process_picture( OD_HTML_Tag_Processor $processor, OD_Tag_Visit
226226
$crossorigin = null;
227227

228228
// Loop through child tags until we reach the closing PICTURE tag.
229-
while ( $processor->next_tag( array( 'tag_closers' => 'visit' ) ) ) {
229+
// As of 1.0.0-beta3, next_tag() allows $query and is beginning to migrate to skip tag closers by default.
230+
// In versions prior to this, the method always visited closers and passing a $query actually threw an exception.
231+
$tag_query = version_compare( OPTIMIZATION_DETECTIVE_VERSION, '1.0.0-beta3', '>=' )
232+
? array( 'tag_closers' => 'visit' )
233+
: null;
234+
while ( $processor->next_tag( $tag_query ) ) {
230235
$tag = $processor->get_tag();
231236

232237
// If we reached the closing PICTURE tag, break.

plugins/image-prioritizer/helper.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@
2121
* @param string $optimization_detective_version Current version of the optimization detective plugin.
2222
*/
2323
function image_prioritizer_init( string $optimization_detective_version ): void {
24-
if (
25-
version_compare( (string) strtok( $optimization_detective_version, '-' ), '1.0.0', '<' )
26-
||
27-
'1.0.0-beta1' === $optimization_detective_version
28-
||
29-
'1.0.0-beta2' === $optimization_detective_version
30-
) {
24+
$required_od_version = '0.9.0';
25+
if ( ! version_compare( (string) strtok( $optimization_detective_version, '-' ), $required_od_version, '>=' ) ) {
3126
add_action(
3227
'admin_notices',
3328
static function (): void {

0 commit comments

Comments
 (0)