Changeset 56704 for trunk/src/wp-includes/blocks.php
- Timestamp:
- 09/26/2023 11:47:18 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks.php
r56683 r56704 724 724 725 725 /** 726 * Retrieves block types (and positions) hooked into the given block.726 * Retrieves block types hooked into the given block, grouped by their relative position. 727 727 * 728 728 * @since 6.4.0 729 729 * 730 * @param string $name Block type name including namespace. 731 * @param string $relative_position Optional. Relative position of the hooked block. Default empty string. 732 * @return array Associative array of `$block_type_name => $position` pairs. 733 */ 734 function get_hooked_blocks( $name, $relative_position = '' ) { 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 ) { 735 734 $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered(); 736 735 $hooked_blocks = array(); … … 739 738 continue; 740 739 } 741 foreach ( $block_type->block_hooks as $anchor_block_type => $ position ) {740 foreach ( $block_type->block_hooks as $anchor_block_type => $relative_position ) { 742 741 if ( $anchor_block_type !== $name ) { 743 742 continue; 744 743 } 745 if ( $relative_position && $relative_position !== $position) {746 continue;747 } 748 $hooked_blocks[ $ block_type->name ] = $position;744 if ( ! isset( $hooked_blocks[ $relative_position ] ) ) { 745 $hooked_blocks[ $relative_position ] = array(); 746 } 747 $hooked_blocks[ $relative_position ][] = $block_type->name; 749 748 } 750 749 } … … 788 787 $relative_position = 'first_child'; 789 788 $anchor_block_type = $parent_block['blockName']; 790 $hooked_block_types = array_keys( get_hooked_blocks( $anchor_block_type, $relative_position ) ); 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 ] 792 : array(); 793 791 794 /** 792 795 * Filters the list of hooked block types for a given anchor block type and relative position. … … 808 811 $relative_position = 'before'; 809 812 $anchor_block_type = $block['blockName']; 810 $hooked_block_types = array_keys( get_hooked_blocks( $anchor_block_type, $relative_position ) ); 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 ] 816 : array(); 817 811 818 /** This filter is documented in wp-includes/blocks.php */ 812 819 $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); … … 850 857 $relative_position = 'after'; 851 858 $anchor_block_type = $block['blockName']; 852 $hooked_block_types = array_keys( get_hooked_blocks( $anchor_block_type, $relative_position ) ); 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(); 863 853 864 /** This filter is documented in wp-includes/blocks.php */ 854 865 $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context ); … … 861 872 $relative_position = 'last_child'; 862 873 $anchor_block_type = $parent_block['blockName']; 863 $hooked_block_types = array_keys( get_hooked_blocks( $anchor_block_type, $relative_position ) ); 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 ] 877 : array(); 878 864 879 /** This filter is documented in wp-includes/blocks.php */ 865 880 $hooked_block_types = apply_filters( 'hooked_block_types', $hooked_block_types, $relative_position, $anchor_block_type, $context );
Note: See TracChangeset
for help on using the changeset viewer.