performance icon indicating copy to clipboard operation
performance copied to clipboard

Reuse template enhancement output buffer in Optimization Detective for WP 6.9

Open westonruter opened this issue 1 year ago • 2 comments

Instead of Optimization Detective hackily opening its own output buffer via od_buffer_output() during the template_include filter:

https://github.com/WordPress/performance/blob/a5c444f27ffc09629005351ed9d0dd77e084ec8b/plugins/optimization-detective/hooks.php#L19

In WordPress 6.9 we can now leverage the template enhancement output buffer introduced via Core-43258 (see r60936). When the wp_start_template_enhancement_output_buffer() function exists, we can skip starting our own output buffer:

if ( ! function_exists( 'wp_start_template_enhancement_output_buffer' ) ) {
    add_filter( 'template_include', 'od_buffer_output', PHP_INT_MAX );
}

And then od_template_output_buffer() can be updated accordingly:

if ( function_exists( 'wp_start_template_enhancement_output_buffer' ) ) {
    add_filter( 'wp_template_enhancement_output_buffer', $callback );
} else {
    add_filter( 'od_template_output_buffer', $callback );
}

westonruter avatar Oct 15 '25 17:10 westonruter

Depends on #2354

westonruter avatar May 26 '26 21:05 westonruter

I've opened #2516 to migrate Optimization Detective to the WordPress 6.9 wp_template_enhancement_output_buffer API for this.

Heads-up that #2514 by @Hug0-Drelon (opened a little earlier today) also addresses this issue — maintainers will likely want to pick one. The two take slightly different approaches:

  • #2514 uses the new hook "when available", keeping the existing od_buffer_output path as a fallback for WordPress < 6.9.
  • #2516 assumes the 6.9 minimum (per #2354), so it drops the function_exists() guard and removes od_buffer_output() entirely. It also adds a backward-compatibility shim (apply_filters_deprecated()) for the now-removed public od_template_output_buffer filter, and updates the docs/tests accordingly.

Happy to defer to #2514 or adapt mine depending on whether the team wants to wait for the 6.9 floor (#2354). Full CI is green on #2516.

MarcinDudekDev avatar Jun 04 '26 13:06 MarcinDudekDev