wppaste
WordPress

WP_Block::render( array $options = array() ): string

Since
5.5.0, 6.5.0
Source
wp-includes/class-wp-block.php:495
Generates the render output for the block.

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()
  • $dynamicbool

    Defaults 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

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
107–166

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 338.

Plugin surface
7 hooks

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.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_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 · 6 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.

WhenInstructionsCalls it makes
empty($computed_attributes) && !$options && empty($value) && $root_interactive_block !== false107–132did_action(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), did_action()
empty($computed_attributes) && !$options && empty($value) && $root_interactive_block === false112–137did_action(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters(), wp_interactivity_process_directives(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), did_action()
empty($computed_attributes) && !$options && empty($value) && $root_interactive_block !== false && $before_wp_enqueue_scripts_count === false && apply_filters()119–140did_action(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), did_action(), apply_filters()
empty($computed_attributes) && !$options && empty($value) && $root_interactive_block === false && $before_wp_enqueue_scripts_count === false && apply_filters()124–145did_action(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters(), wp_interactivity_process_directives(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), did_action(), apply_filters()
empty($computed_attributes) && !$options && empty($value) && $root_interactive_block !== false && $before_wp_enqueue_scripts_count === false && !apply_filters()137–161did_action(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), did_action(), apply_filters(), array_diff(), array_diff(), array_diff()
empty($computed_attributes) && !$options && empty($value) && $root_interactive_block === false && $before_wp_enqueue_scripts_count === false && !apply_filters()142–166did_action(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), apply_filters(), wp_parse_args(), ->process_block_bindings(), apply_filters(), apply_filters(), wp_interactivity_process_directives(), wp_styles(), wp_scripts(), wp_script_modules(), ->get_queue(), did_action(), apply_filters(), array_diff(), array_diff(), array_diff()

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

PHPCompiledExecutedBranchesNotes
8.6-dev338107–16650
8.5338107–16650
8.4338107–166502 fewer instructions than PHP 8.3
8.3340107–16850
8.2340107–16850
8.1340107–16850
7.4340107–16850

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 · 7

7 hooks fire while WP_Block::render() runs, in this order:

  1. apply_filters( interactivity_process_directives )filterline 517 (+22 into the body)

    Filters whether Interactivity API should process directives.

  2. apply_filters( pre_render_block )filterline 555 (+60 into the body)

    Allows render_block() to be short-circuited, by returning a non-null value.

  3. apply_filters( render_block_data )filterline 564 (+69 into the body)

    Filters the block being rendered in render_block(), before it's processed.

  4. apply_filters( render_block_context )filterline 567 (+72 into the body)

    Filters the default context provided to a rendered block.

  5. apply_filters( render_block )filterline 651 (+156 into the body)

    Filters the content of a single block.

  6. apply_filters( render_block_{$this->name} )filterline 666 (+171 into the body)

    Filters the content of a single block.

  7. apply_filters( enqueue_empty_block_content_assets )filterline 704 (+209 into the body)

    Filters whether to enqueue assets for a block which has no rendered content.

Uses · 16

Show all 16

Source code

	public function render( $options = array() ) {		global $post; 		$before_wp_enqueue_scripts_count = did_action( 'wp_enqueue_scripts' ); 		// Capture the current assets queues.		$before_styles_queue         = wp_styles()->queue;		$before_scripts_queue        = wp_scripts()->queue;		$before_script_modules_queue = wp_script_modules()->get_queue(); 		/*		 * 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;						$inner_block_context = $inner_block->context; 						/** 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 ); 						/*						 * The `refresh_context_dependents()` method already calls `refresh_parsed_block_dependents()`.						 * Therefore the second condition is irrelevant if the first one is satisfied.						 */						if ( $inner_block->context !== $inner_block_context ) {							$inner_block->refresh_context_dependents();

Changelog

Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.5.0
Added block bindings processing.from the docblock
5.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.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.