get_comment_delimited_block_content() WordPress Function

The get_comment_delimited_block_content() function is used to get the content of a comment block from a given string. A comment block is a block of text that is delimited by the /* and */ characters. This function will return the content of the comment block, excluding the delimiting characters.

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

Returns the content of a block, including comment delimiters.


Parameters

$block_name

(string|null)(Required)Block name. Null if the block name is unknown, e.g. Classic blocks have their name set to null.

$block_attributes

(array)(Required)Block attributes.

$block_content

(string)(Required)Block save content.


Top ↑

Return

(string) Comment-delimited block content.


Top ↑

Source

File: wp-includes/blocks.php

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
	);
}


Top ↑

Changelog

Changelog
VersionDescription
5.3.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.