wp_start_template_enhancement_output_buffer(): bool
- Since
- 6.9.0
- Source
wp-includes/template.php:869
Description
This function is called immediately before the template is included.
Compatibility
- WordPress
- since 6.9.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.
Return value
bool- Whether the output buffer successfully started.
Performance profile
How much work a call to wp_start_template_enhancement_output_buffer() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 4–13
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 14.
Third-party callbacks on 'wp_template_enhancement_output_buffer_started' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_start_template_enhancement_output_buffer() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!wp_should_output_buffer_template_for_enhancement() | 4 | wp_should_output_buffer_template_for_enhancement() |
wp_should_output_buffer_template_for_enhancement() && !ob_start() | 10 | wp_should_output_buffer_template_for_enhancement(), ob_start() |
wp_should_output_buffer_template_for_enhancement() && ob_start() | 13 | wp_should_output_buffer_template_for_enhancement(), ob_start(), do_action() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 14 | 4–13 | 2 | |
| 8.5 | 14 | 4–13 | 2 | |
| 8.4 | 14 | 4–13 | 2 | |
| 8.3 | 14 | 4–13 | 2 | |
| 8.2 | 14 | 4–13 | 2 | |
| 8.1 | 14 | 4–13 | 2 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 15 | 4–14 | 2 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_start_template_enhancement_output_buffer() runs, in this order:
- do_action( wp_template_enhancement_output_buffer_started )actionline 904 (+35 into the body)
Fires when the template enhancement output buffer has started.
Uses · 2
- wp_should_output_buffer_template_for_enhancement()Checks whether the template should be output buffered for enhancement.
- do_action()Calls the callback functions that have been added to an action hook.
Source code
function wp_start_template_enhancement_output_buffer(): bool { if ( ! wp_should_output_buffer_template_for_enhancement() ) { return false; } $started = ob_start( 'wp_finalize_template_enhancement_output_buffer', 0, // Unlimited buffer size so that entire output is passed to the filter. /* * Instead of the default PHP_OUTPUT_HANDLER_STDFLAGS (cleanable, flushable, and removable) being used for * flags, the PHP_OUTPUT_HANDLER_FLUSHABLE flag must be omitted. If the buffer were flushable, then each time * that ob_flush() is called, a fragment of the output would be sent into the output buffer callback. This * output buffer is intended to capture the entire response for processing, as indicated by the chunk size of 0. * So the buffer does not allow flushing to ensure the entire buffer can be processed, such as for optimizing an * entire HTML document, where markup in the HEAD may need to be adjusted based on markup that appears late in * the BODY. * * If this ends up being problematic, then PHP_OUTPUT_HANDLER_FLUSHABLE could be added to the $flags and the * output buffer callback could check if the phase is PHP_OUTPUT_HANDLER_FLUSH and abort any subsequent * processing while also emitting a _doing_it_wrong(). * * The output buffer needs to be removable because WordPress calls wp_ob_end_flush_all() and then calls * wp_cache_close(). If the buffers are not all flushed before wp_cache_close() is closed, then some output buffer * handlers (e.g. for caching plugins) may fail to be able to store the page output in the object cache. * See <https://github.com/WordPress/performance/pull/1317#issuecomment-2271955356>. */ PHP_OUTPUT_HANDLER_STDFLAGS ^ PHP_OUTPUT_HANDLER_FLUSHABLE ); if ( $started ) { /** * Fires when the template enhancement output buffer has started. * * @since 6.9.0 */ do_action( 'wp_template_enhancement_output_buffer_started' ); } return $started;}Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.