WPDev.one
Core Function
View Source on Trac ↗

traverse_and_serialize_block()

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

Traverses a parsed block tree and applies callbacks before and after serializing it.

Parameters 3 required

Name / Type Description
$block
array

An associative array of a single parsed block object. See WP_Block_Parser_Block.

Required
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.

Required
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.

Required

Return Value

(string)
Serialized block markup.

Function Information

Since Version
6.4.0
Source File
wp-includes/blocks.php
Advertisement