Changeset 56557 for trunk/src/wp-includes/blocks.php
- Timestamp:
- 09/12/2023 01:00:32 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r56527 r56557 795 795 * 796 796 * @since 5.3.1 797 * 798 * @param array $block A representative array of a single parsed block object. See WP_Block_Parser_Block. 797 * @since 6.4.0 The `$callback` parameter was added. 798 * 799 * @param array $block A representative array of a single parsed block object. See WP_Block_Parser_Block. 800 * @param callable|null $callback Optional. Callback to run on each block in the tree before serialization. Default null. 799 801 * @return string String of rendered HTML. 800 802 */ 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 802 808 $block_content = ''; 803 809 804 810 $index = 0; 805 811 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 ); 807 813 } 808 814 … … 823 829 * 824 830 * @since 5.3.1 825 * 826 * @param array[] $blocks An array of representative arrays of parsed block objects. See serialize_block(). 831 * @since 6.4.0 The `$callback` parameter was added. 832 * 833 * @param array[] $blocks An array of representative arrays of parsed block objects. See serialize_block(). 834 * @param callable|null $callback Optional. Callback to run on each block in the tree before serialization. Default null. 827 835 * @return string String of rendered HTML. 828 836 */ 829 function serialize_blocks( $blocks ) { 830 return implode( '', array_map( 'serialize_block', $blocks ) ); 837 function serialize_blocks( $blocks, $callback = null ) { 838 $result = ''; 839 foreach ( $blocks as $block ) { 840 $result .= serialize_block( $block, $callback ); 841 }; 842 return $result; 831 843 } 832 844
Note: See TracChangeset
for help on using the changeset viewer.