@@ -790,20 +790,20 @@ function make_before_block_visitor( $context ) {
790790 * Furthermore, prepend the markup for any blocks hooked `before` the given block and as its parent's
791791 * `first_child`, respectively, to the serialized markup for the given block.
792792 *
793- * @param array $block The block to inject the theme attribute into, and hooked blocks before.
794- * @param array $parent The parent block of the given block.
795- * @param array $prev The previous sibling block of the given block.
793+ * @param array $block The block to inject the theme attribute into, and hooked blocks before.
794+ * @param array $parent_block The parent block of the given block.
795+ * @param array $prev The previous sibling block of the given block.
796796 * @return string The serialized markup for the given block, with the markup for any hooked blocks prepended to it.
797797 */
798- return function ( &$ block , $ parent = null , $ prev = null ) use ( $ context ) {
798+ return function ( &$ block , $ parent_block = null , $ prev = null ) use ( $ context ) {
799799 _inject_theme_attribute_in_template_part_block ( $ block );
800800
801801 $ markup = '' ;
802802
803- if ( $ parent && ! $ prev ) {
803+ if ( $ parent_block && ! $ prev ) {
804804 // Candidate for first-child insertion.
805805 $ relative_position = 'first_child ' ;
806- $ anchor_block_type = $ parent ['blockName ' ];
806+ $ anchor_block_type = $ parent_block ['blockName ' ];
807807 $ hooked_block_types = array_keys ( get_hooked_blocks ( $ anchor_block_type , $ relative_position ) );
808808 /**
809809 * Filters the list of hooked block types for a given anchor block type and relative position.
@@ -856,12 +856,12 @@ function make_after_block_visitor( $context ) {
856856 * Append the markup for any blocks hooked `after` the given block and as its parent's
857857 * `last_child`, respectively, to the serialized markup for the given block.
858858 *
859- * @param array $block The block to inject the hooked blocks after.
860- * @param array $parent The parent block of the given block.
861- * @param array $next The next sibling block of the given block.
859+ * @param array $block The block to inject the hooked blocks after.
860+ * @param array $parent_block The parent block of the given block.
861+ * @param array $next The next sibling block of the given block.
862862 * @return string The serialized markup for the given block, with the markup for any hooked blocks appended to it.
863863 */
864- return function ( &$ block , $ parent = null , $ next = null ) use ( $ context ) {
864+ return function ( &$ block , $ parent_block = null , $ next = null ) use ( $ context ) {
865865 $ markup = '' ;
866866
867867 $ relative_position = 'after ' ;
@@ -873,10 +873,10 @@ function make_after_block_visitor( $context ) {
873873 $ markup .= get_comment_delimited_block_content ( $ hooked_block_type , array (), '' );
874874 }
875875
876- if ( $ parent && ! $ next ) {
876+ if ( $ parent_block && ! $ next ) {
877877 // Candidate for last-child insertion.
878878 $ relative_position = 'last_child ' ;
879- $ anchor_block_type = $ parent ['blockName ' ];
879+ $ anchor_block_type = $ parent_block ['blockName ' ];
880880 $ hooked_block_types = array_keys ( get_hooked_blocks ( $ anchor_block_type , $ relative_position ) );
881881 /** This filter is documented in wp-includes/blocks.php */
882882 $ hooked_block_types = apply_filters ( 'hooked_block_types ' , $ hooked_block_types , $ relative_position , $ anchor_block_type , $ context );
@@ -1059,6 +1059,7 @@ function traverse_and_serialize_block( $block, $pre_callback = null, $post_callb
10591059 $ prev = 0 === $ block_index
10601060 ? null
10611061 : $ block ['innerBlocks ' ][ $ block_index - 1 ];
1062+
10621063 $ block_content .= call_user_func_array (
10631064 $ pre_callback ,
10641065 array ( &$ inner_block , $ block , $ prev )
@@ -1071,12 +1072,13 @@ function traverse_and_serialize_block( $block, $pre_callback = null, $post_callb
10711072 $ next = count ( $ block ['innerBlocks ' ] ) - 1 === $ block_index
10721073 ? null
10731074 : $ block ['innerBlocks ' ][ $ block_index + 1 ];
1075+
10741076 $ block_content .= call_user_func_array (
10751077 $ post_callback ,
10761078 array ( &$ inner_block , $ block , $ next )
10771079 );
10781080 }
1079- $ block_index ++ ;
1081+ ++ $ block_index ;
10801082 }
10811083 }
10821084
@@ -1130,22 +1132,27 @@ function traverse_and_serialize_blocks( $blocks, $pre_callback = null, $post_cal
11301132 $ prev = 0 === $ index
11311133 ? null
11321134 : $ blocks [ $ index - 1 ];
1135+
11331136 $ result .= call_user_func_array (
11341137 $ pre_callback ,
11351138 array ( &$ block , null , $ prev ) // At the top level, there is no parent block to pass to the callback.
11361139 );
11371140 }
1141+
11381142 $ result .= traverse_and_serialize_block ( $ block , $ pre_callback , $ post_callback );
1143+
11391144 if ( is_callable ( $ post_callback ) ) {
11401145 $ next = count ( $ blocks ) - 1 === $ index
11411146 ? null
11421147 : $ blocks [ $ index + 1 ];
1148+
11431149 $ result .= call_user_func_array (
11441150 $ post_callback ,
11451151 array ( &$ block , null , $ next ) // At the top level, there is no parent block to pass to the callback.
11461152 );
11471153 }
11481154 }
1155+
11491156 return $ result ;
11501157}
11511158
0 commit comments