General: Add wp_send_late_headers action which fires right before the template enhancement output buffer is flushed.
This adds a (missing) wp_send_late_headers action which fires right after the wp_template_enhancement_output_buffer filters have applied and right before the output buffer is flushed. The filtered output buffer is passed as an argument to the action so that plugins may do things like send an ETag header which is calculated from the content. This action eliminates the need for plugins to hack the wp_template_enhancement_output_buffer filter with a high priority to send a late response header. This action compliments the send_headers action which is commonly used to send HTTP headers before the template is rendered. Furthermore:
- The template enhancement output buffer is now enabled by default if there is a callback added to either the
wp_template_enhancement_output_buffer filter or the wp_send_late_headers action.
- The
wp_start_template_enhancement_output_buffer() callback for the wp_before_include_template action is increased from the default of 10 to 1000. This goes with the previous point, so that plugins can add those filters and actions during the wp_before_include_template action without having to worry about adding them too late, that is, after wp_start_template_enhancement_output_buffer() has run.
- The
wp_send_late_headers action fires regardless of whether the buffered response is HTML.
Developed in https://github.com/WordPress/wordpress-develop/pull/10381
Follow-up to [60936].
Props westonruter, peterwilsoncc, johnbillion.
See #43258.
Fixes #64126.