render_block_core_block( array $attributes, $content, $block_instance ): string
- Since
- 5.0.0
- Source
wp-includes/blocks/block.php:19
core/block block on server.Compatibility
- WordPress
- since 5.0.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
$attributesarray- The block attributes.
$content$block_instance
Return value
string- Rendered HTML of the referenced block.
Performance profile
How much work a call to render_block_core_block() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 7–82
- Plugin surface
- None
- Called by
- 0
Reaches the database via get_post().
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 112.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
apply_filters()one call below render_block_core_block()
Further down the call graph this can also reach cache, serialize, option 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 render_block_core_block() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($attributes) | 7 | none |
!empty($attributes) | 14–26 | get_post() |
!empty($attributes) && isset($seen_refs) | 27–29 | get_post(), __() |
!empty($attributes) && !isset($seen_refs) && empty($reusable_block) | 73–82 | get_post(), ->run_shortcode(), ->autoembed(), apply_block_hooks_to_content_from_post_object(), parse_blocks(), array_fill(), ->refresh_context_dependents(), ->render() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 112 instructions, 7–82 executed per call, 16 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.
Uses · 5
- get_post()Retrieves post data given a post ID or post object.
- __()Retrieves the translation of $text.
- wp_is_numeric_array()Determines if the variable is a numeric-indexed array.
- apply_block_hooks_to_content_from_post_object()Run the Block Hooks algorithm on a post object's content.
- parse_blocks()Parses blocks out of a content string.
Source code
function render_block_core_block( $attributes, $content, $block_instance ) { static $seen_refs = array(); if ( empty( $attributes['ref'] ) ) { return ''; } $reusable_block = get_post( $attributes['ref'] ); if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) { return ''; } if ( isset( $seen_refs[ $attributes['ref'] ] ) ) { // WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent // is set in `wp_debug_mode()`. $is_debug = WP_DEBUG && WP_DEBUG_DISPLAY; return $is_debug ? // translators: Visible only in the front end, this warning takes the place of a faulty block. __( '[block rendering halted]' ) : ''; } if ( 'publish' !== $reusable_block->post_status || ! empty( $reusable_block->post_password ) ) { return ''; } $seen_refs[ $attributes['ref'] ] = true; // Handle embeds for reusable blocks. global $wp_embed; $content = $wp_embed->run_shortcode( $reusable_block->post_content ); $content = $wp_embed->autoembed( $content ); // Back compat. // For blocks that have not been migrated in the editor, add some back compat // so that front-end rendering continues to work. // This matches the `v2` deprecation. Removes the inner `values` property // from every item. if ( isset( $attributes['content'] ) ) { foreach ( $attributes['content'] as &$content_data ) { if ( isset( $content_data['values'] ) ) { $is_assoc_array = is_array( $content_data['values'] ) && ! wp_is_numeric_array( $content_data['values'] ); if ( $is_assoc_array ) { $content_data = $content_data['values']; } } } } // This matches the `v1` deprecation. Rename `overrides` to `content`. if ( isset( $attributes['overrides'] ) && ! isset( $attributes['content'] ) ) { $attributes['content'] = $attributes['overrides']; } // Apply Block Hooks. $content = apply_block_hooks_to_content_from_post_object( $content, $reusable_block ); /** * We attach the blocks from $content as inner blocks to the Synced Pattern block instance. * This ensures that block context available to the Synced Pattern block instance is provided to * those blocks. */ $block_instance->parsed_block['innerBlocks'] = parse_blocks( $content ); $block_instance->parsed_block['innerContent'] = array_fill( 0, count( $block_instance->parsed_block['innerBlocks'] ), null ); $block_instance->refresh_context_dependents(); $content = $block_instance->render( array( 'dynamic' => false ) ); unset( $seen_refs[ $attributes['ref'] ] ); return $content;}Changelog
Introduced in 5.0.0. 2 changes between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$content added.verified against source$block_instance added.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/blocks/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.