get_hooked_blocks

函数
get_hooked_blocks ( No parameters )
返回值
  • (array[]) Array of block types grouped by anchor block type and the relative position.
定义位置
相关方法
get_allowed_block_typesget_dashboard_blogget_home_urldo_blockswp_get_cookie_login
引入
6.4.0
弃用
-

检索挂接到给定区块的区块类型,按锚区块类型和相对位置分组。

function get_hooked_blocks() {
	$block_types   = WP_Block_Type_Registry::get_instance()->get_all_registered();
	$hooked_blocks = array();
	foreach ( $block_types as $block_type ) {
		if ( ! ( $block_type instanceof WP_Block_Type ) || ! is_array( $block_type->block_hooks ) ) {
			continue;
		}
		foreach ( $block_type->block_hooks as $anchor_block_type => $relative_position ) {
			if ( ! isset( $hooked_blocks[ $anchor_block_type ] ) ) {
				$hooked_blocks[ $anchor_block_type ] = array();
			}
			if ( ! isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] ) ) {
				$hooked_blocks[ $anchor_block_type ][ $relative_position ] = array();
			}
			$hooked_blocks[ $anchor_block_type ][ $relative_position ][] = $block_type->name;
		}
	}

	return $hooked_blocks;
}

常见问题

FAQs
查看更多 >