On this page
get_comment_delimited_block_content( string|null $block_name, array $block_attributes, string $block_content ): string
Returns the content of a block, including comment delimiters.
Parameters
$block_namestring|null Required-
Block name. Null if the block name is unknown, e.g. Classic blocks have their name set to null.
$block_attributesarray Required-
Block attributes.
$block_contentstring Required-
Block save content.
Return
string Comment-delimited block content.
Source
File: wp-includes/blocks.php. View all references
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
);
}
Related
Uses
| Uses | Description |
|---|---|
| strip_core_block_namespace() wp-includes/blocks.php | Returns the block name to use for serialization. This will remove the default “core/” namespace from a block name. |
| serialize_block_attributes() wp-includes/blocks.php | Given an array of attributes, returns a string in the serialized attributes format prepared for post content. |
Used By
| Used By | Description |
|---|---|
| serialize_block() wp-includes/blocks.php | Returns the content of a block, including comment delimiters, serializing all attributes from the given parsed block. |
Changelog
| Version | Description |
|---|---|
| 5.3.1 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_comment_delimited_block_content