get_comment_delimited_block_content( string|null $block_name, array $block_attributes, string $block_content ): string
- Since
- 5.3.1
- Source
wp-includes/blocks.php:1690
Compatibility
- WordPress
- since 5.3.1
- 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
$block_namestring|null- Block name. Null if the block name is unknown, e.g. Classic blocks have their name set to null.
$block_attributesarray- Block attributes.
$block_contentstring- Block save content.
Return value
string- Comment-delimited block content.
Performance profile
How much work a call to get_comment_delimited_block_content() 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
- 6–28
- Plugin surface
- None
- Called by
- 7
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 37.
Nothing here hands control to plugin code.
7 places in core call this, so the cost is paid more often than your own code shows.
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 get_comment_delimited_block_content() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
$block_name === null | 6 | none |
$block_name !== null && empty($block_attributes) | 22–26 | strip_core_block_namespace() |
$block_name !== null && !empty($block_attributes) | 24–28 | strip_core_block_namespace(), serialize_block_attributes() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 37 | 6–28 | 3 | |
| 8.5 | 37 | 6–28 | 3 | |
| 8.4 | 37 | 6–28 | 3 | 2 more instructions than PHP 8.3 |
| 8.3 | 35 | 6–26 | 3 | |
| 8.2 | 35 | 6–26 | 3 | |
| 8.1 | 35 | 6–26 | 3 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 36 | 6–27 | 3 |
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 · 2
- strip_core_block_namespace()Returns the block name to use for serialization. This will remove the default "core/" namespace from a block name.
- serialize_block_attributes()Given an array of attributes, returns a string in the serialized attributes format prepared for post content.
Used by · 7
- _build_block_template_result_from_file()Builds a unified template object based on a theme file.
- _build_block_template_result_from_post()Builds a unified template object based a post Object.
- apply_block_hooks_to_content_from_post_object()Run the Block Hooks algorithm on a post object's content.
- inject_ignored_hooked_blocks_metadata_attributes()Inject ignoredHookedBlocks metadata attributes into a template or template part.
- serialize_block()Returns the content of a block, including comment delimiters, serializing all attributes from the given parsed block.
- traverse_and_serialize_block()Traverses a parsed block tree and applies callbacks before and after serializing it.
- update_ignored_hooked_blocks_postmeta()Updates the wp_postmeta with the list of ignored hooked blocks where the inner blocks are stored as post content.
Source code
function get_comment_delimited_block_content( $block_name, $block_attributes, $block_content ) { if ( is_null( $block_name ) ) { return $block_content; } $serialized_block_name = strip_core_block_namespace( $block_name ); $serialized_attributes = empty( $block_attributes ) ? '' : serialize_block_attributes( $block_attributes ) . ' '; if ( empty( $block_content ) ) { return sprintf( '<!-- wp:%s %s/-->', $serialized_block_name, $serialized_attributes ); } return sprintf( '<!-- wp:%s %s-->%s<!-- /wp:%s -->', $serialized_block_name, $serialized_attributes, $block_content, $serialized_block_name );}Changelog
Introduced in 5.3.1. 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 7.0.4 tag, from
src/wp-includes/blocks.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.