traverse_and_serialize_block


traverse_and_serialize_block ( $block, $pre_callback = null, $post_callback = null )

Access:
  • private
Parameters:
  • (array) block An associative array of a single parsed block object. See WP_Block_Parser_Block.
  • (callable) pre_callback Callback to run on each block in the tree before it is traversed and serialized. It is called with the following arguments: &$block, $parent_block, $previous_block. Its string return value will be prepended to the serialized block markup.
  • (callable) post_callback Callback to run on each block in the tree after it is traversed and serialized. It is called with the following arguments: &$block, $parent_block, $next_block. Its string return value will be appended to the serialized block markup.
See:
Returns:
  • (string) Serialized block markup.
Defined at:

Description

Traverses a parsed block tree and applies callbacks before and after serializing it.Recursively traverses the block and its inner blocks and applies the two callbacks provided as arguments, the first one before serializing the block, and the second one after serializing it. If either callback returns a string value, it will be prepended and appended to the serialized block markup, respectively. The callbacks will receive a reference to the current block as their first argument, so that they can also modify it, and the current block's parent block as second argument. Finally, the `$pre_callback` receives the previous block, whereas the `$post_callback` receives the next block as third argument. Serialized blocks are returned including comment delimiters, and with all attributes serialized. This function should be used when there is a need to modify the saved block, or to inject markup into the return value. Prefer `serialize_block` when preparing a block to be saved to post content. This function is meant for internal use only.

Related Functions

traverse_and_serialize_blocks, serialize_block, serialize_blocks, remove_serialized_parent_block, extract_serialized_parent_block

Top Google Results

User discussions

wpseek mobile