wp_should_output_buffer_template_for_enhancement
概述
此文档介绍 wp_should_output_buffer_template_for_enhancement 过滤器,用于控制模板是否应启用输出缓冲以支持增强功能。默认情况下,输出缓冲的启动依赖于特定钩子的存在,此过滤器允许在模板渲染过程中动态调整缓冲行为。
关键要点
- 过滤器名称:wp_should_output_buffer_template_for_enhancement
- 参数:$use_output_buffer(布尔值),决定是否启动输出缓冲
- 默认行为:输出缓冲仅在存在 wp_template_enhancement_output_buffer 过滤器或 wp_finalized_template_enhancement_output_buffer 动作时启动
- 触发时机:钩子必须在 wp_before_include_template 动作前添加,否则默认不缓冲
- 用途:允许站点在模板渲染后期选择性地启用增强功能,避免不必要的缓冲影响流式响应
- 相关函数:wp_should_output_buffer_template_for_enhancement() 用于检查缓冲状态
- 引入版本:WordPress 6.9.0
Filters whether the template should be output-buffered for enhancement.
Description
By default, an output buffer is only started if a ‘wp_template_enhancement_output_buffer’ filter has been added or if a plugin has added a ‘wp_finalized_template_enhancement_output_buffer’ action. For this default to apply, either of the hooks must be added by the time the template is included at the ‘wp_before_include_template’ action. This allows template responses to be streamed unless the there is code which depends on an output buffer being opened. This filter allows a site to opt in to adding such template enhancement filters later during the rendering of the template.
Parameters
$use_output_bufferbool-
Whether an output buffer is started.
Source
return (bool) apply_filters( 'wp_should_output_buffer_template_for_enhancement', has_filter( 'wp_template_enhancement_output_buffer' ) || has_action( 'wp_finalized_template_enhancement_output_buffer' ) );
Changelog
| Version | Description |
|---|---|
| 6.9.0 | Introduced. |