Optimization Detective: Reuse the WordPress 6.9 template enhancement output buffer#2516
Conversation
…output buffer. Instead of opening its own output buffer at the template_include filter via od_buffer_output() and exposing the od_template_output_buffer filter, the optimization callback is now registered on the wp_template_enhancement_output_buffer filter introduced in WordPress 6.9 (Core-43258, r60936). Registering the filter also opts in to starting the core output buffer; when the response is not eligible for optimization, no buffer is started and the response is streamed. This removes the od_buffer_output() function, the template_include hook, and the plugin-specific od_template_output_buffer filter (documented removal). Requires the minimum WordPress version to be 6.9. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2516 +/- ##
==========================================
- Coverage 69.29% 69.29% -0.01%
==========================================
Files 90 90
Lines 7723 7721 -2
==========================================
- Hits 5352 5350 -2
Misses 2371 2371
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Reuses the WordPress 6.9 template enhancement output buffer (Core-43258, see r60936) instead of Optimization Detective opening its own output buffer.
od_buffer_output()function and itstemplate_includehook (the "hack" referenced in its own docblock).od_maybe_add_template_output_buffer_filter()now registers the optimization callback on the corewp_template_enhancement_output_bufferfilter. Registering the filter on thewpaction (before core opens the buffer atwp_before_include_templatepriority 1000) opts in to the core buffer; when the response is not eligible for optimization, no filter is added and the response streams (an improvement over the old code, which always opened a passthrough buffer).Fixes #2224.
Backward compatibility
The previously public, documented
od_template_output_bufferfilter is replaced by core'swp_template_enhancement_output_buffer. To avoid silently breaking any third-party callbacks, a backward-compatibility shim still appliesod_template_output_bufferviaapply_filters_deprecated()(emits a deprecation notice only when the filter actually has listeners). The entry was removed fromdocs/hooks.mdanddocs/introduction.mdwas updated.Dependency
function_exists()guards. Please land after/with the 6.9 minimum-version bump. (Companion to #2225, which performs the same migration for Performance Lab's Server-Timing.)Known limitation
Core's buffer starts at
wp_before_include_template, which only fires when the resolved template is a readable file. On routes where no readable template is included, optimization is not applied. This is an accepted trade-off of reusing the core buffer.Test plan
od_buffer_output()'s buffer mechanics (now owned by core).wp_template_enhancement_output_buffer.od_template_output_bufferfilter is still applied (with@expectedDeprecated).optimization-detectivetestsuite: 355 tests, 12141 assertions — green on WP 7.0 (which includes the 6.9 API).image-prioritizer+embed-optimizer(OD consumers): green.phpcs+phpstanpass.AI assistance
AI assistance: Yes
Tool(s): Claude Code (Anthropic)
Model(s): Claude Opus 4.8
Used for: Implementation, test updates, and code review (cross-checked with Grok); I have reviewed and take responsibility for the output.