Skip to content

Commit b926b86

Browse files
committed
Add callback arg to serialize_blocks
1 parent 77a7772 commit b926b86

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/wp-includes/blocks.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,16 +794,22 @@ function get_comment_delimited_block_content( $block_name, $block_attributes, $b
794794
* instead preserve the markup as parsed.
795795
*
796796
* @since 5.3.1
797+
* @since 6.4.0 The `$callback` parameter was added.
797798
*
798799
* @param array $block A representative array of a single parsed block object. See WP_Block_Parser_Block.
800+
* @param string $callback Optional. Callback to run on the block before serialization.
799801
* @return string String of rendered HTML.
800802
*/
801-
function serialize_block( $block ) {
803+
function serialize_block( $block, $callback = null ) {
804+
if ( is_callable( $callback ) ) {
805+
$block = call_user_func( $callback, $block );
806+
}
807+
802808
$block_content = '';
803809

804810
$index = 0;
805811
foreach ( $block['innerContent'] as $chunk ) {
806-
$block_content .= is_string( $chunk ) ? $chunk : serialize_block( $block['innerBlocks'][ $index++ ] );
812+
$block_content .= is_string( $chunk ) ? $chunk : serialize_block( $block['innerBlocks'][ $index++ ], $callback );
807813
}
808814

809815
if ( ! is_array( $block['attrs'] ) ) {

0 commit comments

Comments
 (0)