Reuse template enhancement output buffer in Optimization Detective for WP 6.9
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 );
}
Depends on #2354
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_outputpath as a fallback for WordPress < 6.9. - #2516 assumes the 6.9 minimum (per #2354), so it drops the
function_exists()guard and removesod_buffer_output()entirely. It also adds a backward-compatibility shim (apply_filters_deprecated()) for the now-removed publicod_template_output_bufferfilter, 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.