Account for OPTIMIZATION_DETECTIVE_VERSION not always being defined for Embed Optimizer#1908
Conversation
…or Embed Optimizer
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## trunk #1908 +/- ##
=======================================
Coverage 69.63% 69.63%
=======================================
Files 86 86
Lines 6991 6991
=======================================
Hits 4868 4868
Misses 2123 2123
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
| // As of 1.0.0-beta3, next_tag() allows $query and is beginning to migrate to skip tag closers by default. | ||
| // In versions prior to this, the method always visited closers and passing a $query actually threw an exception. | ||
| $tag_query = version_compare( OPTIMIZATION_DETECTIVE_VERSION, '1.0.0-beta3', '>=' ) | ||
| $tag_query = ! defined( 'OPTIMIZATION_DETECTIVE_VERSION' ) || version_compare( OPTIMIZATION_DETECTIVE_VERSION, '1.0.0-beta3', '>=' ) |
There was a problem hiding this comment.
Why is this function's logic running even when Optimization Detective is not active? Is it not something that relies on that plugin?
Also, looking at this again: Why does the Optimization Detective matter for this, given it's passed to the WP_HTML_Tag_Processor instance, which should depend on Core, not OD? Maybe I'm missing something here.
There was a problem hiding this comment.
Embed Optimizer does not require Optimization Detective. Without Optimization Detective, it lazy-loads all embeds.
When OD is not active, a WP_HTML_Tag_Processor instance is passed. When OD is active, then an OD_HTML_Tag_Processor instance is passed (a subclass of WP_HTML_Tag_Processor).
There was a problem hiding this comment.
Makes sense, thanks.
I didn't know Embed Optimizer was doing this already on its own (albeit less reliably of course).
There was a problem hiding this comment.
I'm just realizing that this change and #1872 probably fix Embed Optimizer to work properly when OD is not active, actually. Because the default behavior of next_tag() is to not visit tag closers, and yet the OD subclass was visiting tag closers by default... since no query was being passed in, when OD is not active then it would be skipping all tag closers and the logic that checks $processor->is_tag_closer() would always return false.
There was a problem hiding this comment.
Nevermind. The only part of the code that uses is_tag_closer() is for the non-OD context:
performance/plugins/embed-optimizer/hooks.php
Lines 212 to 234 in 20fea77
So there wouldn't have been a bug.

I was doing some testing with Optimization Detective deactivated but with Embed Optimizer active. I started getting a fatal error:
This issue was introduced in #1872. It is an issue unique to Embed Optimizer because it does not require Optimization Detective but merely suggests it. This means the
OPTIMIZATION_DETECTIVE_VERSIONconstant is not guaranteed to be defined. It's not needed by Image Prioritizer since it initializes at theod_initaction so we guaranteed that the constant will be available.