Blocks: Introduce a variation of serialize blocks helper with traversing

Introduces two new functions `traverse_and_serialize_blocks` and `traverse_and_serialize_block` with the additional `$callback` argument. It is possible to pass parent block, block index, chunk index to the callback argument.

Reverts changes applied to `serialize_blocks` and `serialize_block` in #59327 with [56557].

Props ockham, mukesh27.
See #59313.




git-svn-id: https://develop.svn.wordpress.org/trunk@56620 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Greg Ziółkowski
2023-09-19 12:48:41 +00:00
parent 3916624c13
commit 48b9b6cbab
3 changed files with 105 additions and 21 deletions

View File

@@ -609,7 +609,7 @@ function _build_block_template_result_from_file( $template_file, $template_type
}
$blocks = parse_blocks( $template_content );
$template->content = serialize_blocks( $blocks, '_inject_theme_attribute_in_template_part_block' );
$template->content = traverse_and_serialize_blocks( $blocks, '_inject_theme_attribute_in_template_part_block' );
return $template;
}