render_block_core_pattern( array $attributes ): string
- Since
- 6.3.0
- Source
wp-includes/blocks/pattern.php:33
core/pattern block on the server.Compatibility
- WordPress
- since 6.3.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- Block attributes.
Return value
string- Returns the output of the pattern.
Performance profile
How much work a call to render_block_core_pattern() 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
- 5–51
- Plugin surface
- None
- 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 68.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below render_block_core_pattern()
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 render_block_core_pattern() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($attributes) | 5 | none |
!empty($attributes) | 13–22 | ::WP_Block_Patterns_Registry(), ->is_registered() |
!empty($attributes) && ->is_registered() && isset($seen_refs) | 27–29 | ::WP_Block_Patterns_Registry(), ->is_registered(), __(), sprintf() |
!empty($attributes) && ->is_registered() && !isset($seen_refs) | 37–39 | ::WP_Block_Patterns_Registry(), ->is_registered(), ->get_registered(), do_blocks(), ->autoembed() |
!empty($attributes) && ->is_registered() && !isset($seen_refs) && defined('IS_GUTENBERG_PLUGIN') && function_exists() | 43 | ::WP_Block_Patterns_Registry(), ->is_registered(), ->get_registered(), function_exists(), do_blocks(), ->autoembed() |
!empty($attributes) && ->is_registered() && !isset($seen_refs) && defined('IS_GUTENBERG_PLUGIN') && !function_exists() | 51 | ::WP_Block_Patterns_Registry(), ->is_registered(), ->get_registered(), function_exists(), parse_blocks(), gutenberg_serialize_blocks(), do_blocks(), ->autoembed() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 68 instructions, 5–51 executed per call, 8 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 · 4
- __()Retrieves the translation of $text.
- parse_blocks()Parses blocks out of a content string.
- do_blocks()Parses dynamic blocks out of `post_content` and re-renders them.
- WP_Block_Patterns_Registry::get_instance()Utility method to retrieve the main instance of the class.
Source code
function render_block_core_pattern( $attributes ) { static $seen_refs = array(); if ( empty( $attributes['slug'] ) ) { return ''; } $slug = $attributes['slug']; $registry = WP_Block_Patterns_Registry::get_instance(); if ( ! $registry->is_registered( $slug ) ) { return ''; } if ( isset( $seen_refs[ $attributes['slug'] ] ) ) { // 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. %s represents a pattern's slug. sprintf( __( '[block rendering halted for pattern "%s"]' ), $slug ) : ''; } $pattern = $registry->get_registered( $slug ); $content = $pattern['content']; // Backward compatibility for handling Block Hooks and injecting the theme attribute in the Gutenberg plugin. // This can be removed when the minimum supported WordPress is >= 6.4. if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && ! function_exists( 'traverse_and_serialize_blocks' ) ) { $blocks = parse_blocks( $content ); $content = gutenberg_serialize_blocks( $blocks ); } $seen_refs[ $attributes['slug'] ] = true; $content = do_blocks( $content ); global $wp_embed; $content = $wp_embed->autoembed( $content ); unset( $seen_refs[ $attributes['slug'] ] ); return $content;}Changelog
Introduced in 6.3.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/blocks/pattern.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.