WP_Block::render( array $options = array() ): string
- Since
- 5.5.0, 6.5.0
- Source
wp-includes/class-wp-block.php:451
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$optionsarrayoptional- Optional options object.Default:
array()$dynamicboolDefaults to 'true'. Optionally set to false to avoid using the block's render_callback.
Return value
string- Rendered block output.
Performance profile
How much work a call to WP_Block::render() 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
- Light
- Scaling
- Scales with input
- Instructions
- 73–127
- Plugin surface
- 6 hooks
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 244.
Third-party callbacks on 'interactivity_process_directives', 'pre_render_block', 'render_block_data' 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
apply_filters()called directly
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Block::render() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($computed_attributes) && !$options && $root_interactive_block !== false | 73–103 | apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters() |
empty($computed_attributes) && !$options && $root_interactive_block === false | 78–108 | apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters(), wp_interactivity_process_directives() |
empty($computed_attributes) && !$options && $root_interactive_block !== false | 92–122 | apply_filters(), wp_parse_args(), ->process_block_bindings(), call_user_func(), apply_filters(), apply_filters() |
empty($computed_attributes) && !$options && $root_interactive_block === false | 97–127 | apply_filters(), wp_parse_args(), ->process_block_bindings(), call_user_func(), apply_filters(), apply_filters(), wp_interactivity_process_directives() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 244 instructions, 73–127 executed per call, 36 branches. The work does not change between versions.
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 · 6
6 hooks fire while WP_Block::render() runs, in this order:
- apply_filters( interactivity_process_directives )filterline 466 (+15 into the body)
Filters whether Interactivity API should process directives.
- apply_filters( pre_render_block )filterline 504 (+53 into the body)
Allows render_block() to be short-circuited, by returning a non-null value.
- apply_filters( render_block_data )filterline 512 (+61 into the body)
Filters the block being rendered in render_block(), before it's processed.
- apply_filters( render_block_context )filterline 515 (+64 into the body)
Filters the default context provided to a rendered block.
- apply_filters( render_block )filterline 584 (+133 into the body)
Filters the content of a single block.
- apply_filters( render_block_{$this->name} )filterline 599 (+148 into the body)
Filters the content of a single block.
Uses · 8
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_parse_args()Merges user defined arguments into defaults array.
- wp_enqueue_script()Enqueues a script.
- wp_enqueue_script_module()Marks the script module to be enqueued in the page.
- wp_enqueue_style()Enqueues a CSS stylesheet.
- wp_interactivity_process_directives()Processes the interactivity directives contained within the HTML content and updates the markup accordingly.
- WP_Block::process_block_bindings()Processes the block bindings and updates the block attributes with the values from the sources.
- WP_Block::replace_html()Depending on the block attribute name, replace its value in the HTML based on the value provided.
Source code
public function render( $options = array() ) { global $post; /* * There can be only one root interactive block at a time because the rendered HTML of that block contains * the rendered HTML of all its inner blocks, including any interactive block. */ static $root_interactive_block = null; /** * Filters whether Interactivity API should process directives. * * @since 6.6.0 * * @param bool $enabled Whether the directives processing is enabled. */ $interactivity_process_directives_enabled = apply_filters( 'interactivity_process_directives', true ); if ( $interactivity_process_directives_enabled && null === $root_interactive_block && ( ( isset( $this->block_type->supports['interactivity'] ) && true === $this->block_type->supports['interactivity'] ) || ! empty( $this->block_type->supports['interactivity']['interactive'] ) ) ) { $root_interactive_block = $this; } $options = wp_parse_args( $options, array( 'dynamic' => true, ) ); // Process the block bindings and get attributes updated with the values from the sources. $computed_attributes = $this->process_block_bindings(); if ( ! empty( $computed_attributes ) ) { // Merge the computed attributes with the original attributes. $this->attributes = array_merge( $this->attributes, $computed_attributes ); } $is_dynamic = $options['dynamic'] && $this->name && null !== $this->block_type && $this->block_type->is_dynamic(); $block_content = ''; if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) { $index = 0; foreach ( $this->inner_content as $chunk ) { if ( is_string( $chunk ) ) { $block_content .= $chunk; } else { $inner_block = $this->inner_blocks[ $index ]; $parent_block = $this; /** This filter is documented in wp-includes/blocks.php */ $pre_render = apply_filters( 'pre_render_block', null, $inner_block->parsed_block, $parent_block ); if ( ! is_null( $pre_render ) ) { $block_content .= $pre_render; } else { $source_block = $inner_block->parsed_block; /** This filter is documented in wp-includes/blocks.php */ $inner_block->parsed_block = apply_filters( 'render_block_data', $inner_block->parsed_block, $source_block, $parent_block ); /** This filter is documented in wp-includes/blocks.php */ $inner_block->context = apply_filters( 'render_block_context', $inner_block->context, $inner_block->parsed_block, $parent_block ); $block_content .= $inner_block->render(); } ++$index; } } } if ( ! empty( $computed_attributes ) && ! empty( $block_content ) ) { foreach ( $computed_attributes as $attribute_name => $source_value ) { $block_content = $this->replace_html( $block_content, $attribute_name, $source_value ); } }Changelog
Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/class-wp-block.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.