WP_Block_Patterns_Registry::prepare_content( array $pattern, array $hooked_blocks ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Prepares the content of a block pattern. If hooked blocks are registered, they get injected into the pattern, when they met the defined criteria.

Parameters

$patternarrayrequired
Registered pattern properties.
$hooked_blocksarrayrequired
The list of hooked blocks.

Return

string The content of the block pattern.

Source

private function prepare_content( $pattern, $hooked_blocks ) {
	$content = $pattern['content'];

	$before_block_visitor = '_inject_theme_attribute_in_template_part_block';
	$after_block_visitor  = null;
	if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) {
		$before_block_visitor = make_before_block_visitor( $hooked_blocks, $pattern );
		$after_block_visitor  = make_after_block_visitor( $hooked_blocks, $pattern );
	}
	$blocks  = parse_blocks( $content );
	$content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor );

	return $content;
}

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

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