get_comment_delimited_block_content( string|null $block_name, array $block_attributes, string $block_content ): string

In this article

Returns the content of a block, including comment delimiters.

Parameters

$block_namestring|nullrequired
Block name. Null if the block name is unknown, e.g. Classic blocks have their name set to null.
$block_attributesarrayrequired
Block attributes.
$block_contentstringrequired
Block save content.

Return

string Comment-delimited block content.

Source

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

VersionDescription
5.3.1Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.