Changeset 56970
- Timestamp:
- 10/18/2023 07:30:40 PM (14 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r56960 r56970 1063 1063 } 1064 1064 1065 $block_content .= traverse_and_serialize_block( $inner_block, $pre_callback, $post_callback );1066 1067 1065 if ( is_callable( $post_callback ) ) { 1068 1066 $next = count( $block['innerBlocks'] ) - 1 === $block_index … … 1070 1068 : $block['innerBlocks'][ $block_index + 1 ]; 1071 1069 1072 $ block_content .= call_user_func_array(1070 $post_markup = call_user_func_array( 1073 1071 $post_callback, 1074 1072 array( &$inner_block, $block, $next ) 1075 1073 ); 1076 1074 } 1075 1076 $block_content .= traverse_and_serialize_block( $inner_block, $pre_callback, $post_callback ); 1077 $block_content .= isset( $post_markup ) ? $post_markup : ''; 1078 1077 1079 ++$block_index; 1078 1080 } … … 1136 1138 } 1137 1139 1138 $result .= traverse_and_serialize_block( $block, $pre_callback, $post_callback );1139 1140 1140 if ( is_callable( $post_callback ) ) { 1141 1141 $next = count( $blocks ) - 1 === $index … … 1143 1143 : $blocks[ $index + 1 ]; 1144 1144 1145 $ result .= call_user_func_array(1145 $post_markup = call_user_func_array( 1146 1146 $post_callback, 1147 1147 array( &$block, null, $next ) // At the top level, there is no parent block to pass to the callback. 1148 1148 ); 1149 1149 } 1150 1151 $result .= traverse_and_serialize_block( $block, $pre_callback, $post_callback ); 1152 $result .= isset( $post_markup ) ? $post_markup : ''; 1150 1153 } 1151 1154 -
trunk/tests/phpunit/tests/blocks/serialize.php
r56701 r56970 75 75 } 76 76 77 /** 78 * @ticket 59669 79 * 80 * @covers ::traverse_and_serialize_blocks 81 */ 82 public function test_traverse_and_serialize_blocks_post_callback_modifies_current_block() { 83 $markup = "<!-- wp:outer --><!-- wp:inner {\"key\":\"value\"} -->Example.<!-- /wp:inner -->\n\nExample.\n\n<!-- wp:void /--><!-- /wp:outer -->"; 84 $blocks = parse_blocks( $markup ); 85 86 $actual = traverse_and_serialize_blocks( $blocks, null, array( __CLASS__, 'add_attribute_to_inner_block' ) ); 87 88 $this->assertSame( 89 "<!-- wp:outer --><!-- wp:inner {\"key\":\"value\",\"myattr\":\"myvalue\"} -->Example.<!-- /wp:inner -->\n\nExample.\n\n<!-- wp:void /--><!-- /wp:outer -->", 90 $actual 91 ); 92 } 93 77 94 public static function add_attribute_to_inner_block( &$block ) { 78 95 if ( 'core/inner' === $block['blockName'] ) {
Note: See TracChangeset
for help on using the changeset viewer.