Skip to content

Optimization Detective: Reuse the WordPress 6.9 template enhancement output buffer#2516

Open
MarcinDudekDev wants to merge 2 commits into
WordPress:trunkfrom
MarcinDudekDev:feature/2224-od-template-enhancement-buffer
Open

Optimization Detective: Reuse the WordPress 6.9 template enhancement output buffer#2516
MarcinDudekDev wants to merge 2 commits into
WordPress:trunkfrom
MarcinDudekDev:feature/2224-od-template-enhancement-buffer

Conversation

@MarcinDudekDev

Copy link
Copy Markdown

Summary

Reuses the WordPress 6.9 template enhancement output buffer (Core-43258, see r60936) instead of Optimization Detective opening its own output buffer.

  • Removes the od_buffer_output() function and its template_include hook (the "hack" referenced in its own docblock).
  • od_maybe_add_template_output_buffer_filter() now registers the optimization callback on the core wp_template_enhancement_output_buffer filter. Registering the filter on the wp action (before core opens the buffer at wp_before_include_template priority 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_buffer filter is replaced by core's wp_template_enhancement_output_buffer. To avoid silently breaking any third-party callbacks, a backward-compatibility shim still applies od_template_output_buffer via apply_filters_deprecated() (emits a deprecation notice only when the filter actually has listeners). The entry was removed from docs/hooks.md and docs/introduction.md was updated.

Dependency

⚠️ This requires the minimum WordPress version to be 6.9 (#2354). The new hooks/functions only exist in 6.9+, and this PR intentionally omits 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

  • Removed the two tests that exercised od_buffer_output()'s buffer mechanics (now owned by core).
  • Updated the eligibility test to assert registration on wp_template_enhancement_output_buffer.
  • Added a test verifying the deprecated od_template_output_buffer filter is still applied (with @expectedDeprecated).
  • optimization-detective testsuite: 355 tests, 12141 assertions — green on WP 7.0 (which includes the 6.9 API).
  • image-prioritizer + embed-optimizer (OD consumers): green.
  • phpcs + phpstan pass.

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.

…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>
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: MarcinDudekDev <myththrazz@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.29%. Comparing base (4cbab3d) to head (99afc96).

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              
Flag Coverage Δ
multisite 69.29% <100.00%> (-0.01%) ⬇️
single 35.64% <0.00%> (-0.13%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@westonruter westonruter added [Type] Enhancement A suggestion for improvement of an existing feature [Plugin] Optimization Detective Issues for the Optimization Detective plugin labels Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Optimization Detective Issues for the Optimization Detective plugin [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reuse template enhancement output buffer in Optimization Detective for WP 6.9

2 participants