Changeset 56805 for trunk/src/wp-includes/blocks.php
- Timestamp:
- 10/09/2023 04:38:25 PM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r56753 r56805 724 724 725 725 /** 726 * Retrieves block types hooked into the given block, grouped by theirrelative position.726 * Retrieves block types hooked into the given block, grouped by anchor block type and the relative position. 727 727 * 728 728 * @since 6.4.0 729 729 * 730 * @param string $name Block type name including namespace. 731 * @return array[] Array of block types grouped by their relative position. 732 */ 733 function get_hooked_blocks( $name ) { 730 * @return array[] Array of block types grouped by anchor block type and the relative position. 731 */ 732 function get_hooked_blocks() { 734 733 $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered(); 735 734 $hooked_blocks = array(); … … 739 738 } 740 739 foreach ( $block_type->block_hooks as $anchor_block_type => $relative_position ) { 741 if ( $anchor_block_type !== $name ) { 742 continue; 743 } 744 if ( ! isset( $hooked_blocks[ $relative_position ] ) ) { 745 $hooked_blocks[ $relative_position ] = array(); 746 } 747 $hooked_blocks[ $relative_position ][] = $block_type->name; 748 } 749 } 740 if ( ! isset( $hooked_blocks[ $anchor_block_type ] ) ) { 741 $hooked_blocks[ $anchor_block_type ] = array(); 742 } 743 if ( ! isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) ) { 744 $hooked_blocks[ $anchor_block_type ][ $relative_position ] = array(); 745 } 746 $hooked_blocks[ $anchor_block_type ][ $relative_position ][] = $block_type->name; 747 } 748 } 749 750 750 return $hooked_blocks; 751 751 } … … 761 761 * @access private 762 762 * 763 * @param WP_Block_Template|array $context A block template, template part, or pattern that the blocks belong to. 763 * @param array $hooked_blocks An array of blocks hooked to another given block. 764 * @param WP_Block_Template|array $context A block template, template part, or pattern that the blocks belong to. 764 765 * @return callable A function that returns the serialized markup for the given block, 765 766 * including the markup for any hooked blocks before it. 766 767 */ 767 function make_before_block_visitor( $ context ) {768 function make_before_block_visitor( $hooked_blocks, $context ) { 768 769 /** 769 770 * Injects hooked blocks before the given block, injects the `theme` attribute into Template Part blocks, and returns the serialized markup. … … 778 779 * @return string The serialized markup for the given block, with the markup for any hooked blocks prepended to it. 779 780 */ 780 return function ( &$block, $parent_block = null, $prev = null ) use ( $ context ) {781 return function ( &$block, $parent_block = null, $prev = null ) use ( $hooked_blocks, $context ) { 781 782 _inject_theme_attribute_in_template_part_block( $block ); 782 783 … … 787 788 $relative_position = 'first_child'; 788 789 $anchor_block_type = $parent_block['blockName']; 789 $hooked_block_types = get_hooked_blocks( $anchor_block_type ); 790 $hooked_block_types = isset( $hooked_block_types[ $relative_position ] ) 791 ? $hooked_block_types[ $relative_position ] 790 $hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) 791 ? $hooked_blocks[ $anchor_block_type ][ $relative_position ] 792 792 : array(); 793 793 … … 811 811 $relative_position = 'before'; 812 812 $anchor_block_type = $block['blockName']; 813 $hooked_block_types = get_hooked_blocks( $anchor_block_type ); 814 $hooked_block_types = isset( $hooked_block_types[ $relative_position ] ) 815 ? $hooked_block_types[ $relative_position ] 813 $hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) 814 ? $hooked_blocks[ $anchor_block_type ][ $relative_position ] 816 815 : array(); 817 816 … … 836 835 * @access private 837 836 * 838 * @param WP_Block_Template|array $context A block template, template part, or pattern that the blocks belong to. 837 * @param array $hooked_blocks An array of blocks hooked to another block. 838 * @param WP_Block_Template|array $context A block template, template part, or pattern that the blocks belong to. 839 839 * @return callable A function that returns the serialized markup for the given block, 840 840 * including the markup for any hooked blocks after it. 841 841 */ 842 function make_after_block_visitor( $ context ) {842 function make_after_block_visitor( $hooked_blocks, $context ) { 843 843 /** 844 844 * Injects hooked blocks after the given block, and returns the serialized markup. … … 852 852 * @return string The serialized markup for the given block, with the markup for any hooked blocks appended to it. 853 853 */ 854 return function ( &$block, $parent_block = null, $next = null ) use ( $ context ) {854 return function ( &$block, $parent_block = null, $next = null ) use ( $hooked_blocks, $context ) { 855 855 $markup = ''; 856 856 857 857 $relative_position = 'after'; 858 858 $anchor_block_type = $block['blockName']; 859 $hooked_block_types = get_hooked_blocks( $anchor_block_type ); 860 $hooked_block_types = isset( $hooked_block_types[ $relative_position ] ) 861 ? $hooked_block_types[ $relative_position ] 862 : array(); 859 $hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) 860 ? $hooked_blocks[ $anchor_block_type ][ $relative_position ] 861 : array(); 863 862 864 863 /** This filter is documented in wp-includes/blocks.php */ … … 872 871 $relative_position = 'last_child'; 873 872 $anchor_block_type = $parent_block['blockName']; 874 $hooked_block_types = get_hooked_blocks( $anchor_block_type ); 875 $hooked_block_types = isset( $hooked_block_types[ $relative_position ] ) 876 ? $hooked_block_types[ $relative_position ] 873 $hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) 874 ? $hooked_blocks[ $anchor_block_type ][ $relative_position ] 877 875 : array(); 878 876
Note: See TracChangeset
for help on using the changeset viewer.