@@ -844,16 +844,17 @@ function wp_should_output_buffer_template_for_enhancement(): bool {
844844 * Filters whether the template should be output-buffered for enhancement.
845845 *
846846 * By default, an output buffer is only started if a {@see 'wp_template_enhancement_output_buffer'} filter has been
847- * added. For this default to apply, a filter must be added by the time the template is included at the
848- * {@see 'wp_before_include_template'} action. This allows template responses to be streamed as much as possible
849- * when no template enhancements are registered to apply. This filter allows a site to opt in to adding such
850- * template enhancement filters during the rendering of the template.
847+ * added or if a plugin has added a {@see 'send_late_headers'} action. For this default to apply, a filter must be
848+ * added by the time the template is included at the {@see 'wp_before_include_template'} action. This allows
849+ * template responses to be streamed as much as possible when no template enhancements are registered to apply.
850+ * This filter allows a site to opt in to adding such template enhancement filters during the rendering of the
851+ * template.
851852 *
852853 * @since 6.9.0
853854 *
854855 * @param bool $use_output_buffer Whether an output buffer is started.
855856 */
856- return (bool ) apply_filters ( 'wp_should_output_buffer_template_for_enhancement ' , has_filter ( 'wp_template_enhancement_output_buffer ' ) );
857+ return (bool ) apply_filters ( 'wp_should_output_buffer_template_for_enhancement ' , has_filter ( 'wp_template_enhancement_output_buffer ' ) || has_action ( ' send_late_headers ' ) );
857858}
858859
859860/**
@@ -977,5 +978,18 @@ function wp_finalize_template_enhancement_output_buffer( string $output, int $ph
977978 * @param string $filtered_output HTML template enhancement output buffer.
978979 * @param string $output Original HTML template output buffer.
979980 */
980- return (string ) apply_filters ( 'wp_template_enhancement_output_buffer ' , $ filtered_output , $ output );
981+ $ filtered_output = (string ) apply_filters ( 'wp_template_enhancement_output_buffer ' , $ filtered_output , $ output );
982+
983+ /**
984+ * Fires at the last moment HTTP headers may be sent.
985+ *
986+ * This happens immediately after the template enhancement output buffer has been processed.
987+ *
988+ * @since 6.9.0
989+ *
990+ * @param string $filtered_output Filtered output buffer.
991+ */
992+ do_action ( 'send_late_headers ' , $ filtered_output );
993+
994+ return $ filtered_output ;
981995}
0 commit comments