WPDev.one
Core Function
View Source on Trac ↗

traverse_and_serialize_blocks()

traverse_and_serialize_blocks( mixed $blocks, mixed $pre_callback = null, mixed $post_callback = null )

Given an array of parsed block trees, applies callbacks before and after serializing them and

Parameters 3 required

Name / Type Description
$blocks
array[]

An array of parsed blocks. 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