wp_get_first_block

函数
wp_get_first_block ( $blocks, $block_name )
参数
  • (array) $blocks Array of blocks.
    Required:
  • (string) $block_name Name of the block to find.
    Required:
返回值
  • (array) Found block, or empty array if none found.
定义位置
相关方法
wp_set_post_lockwp_check_post_lock_get_list_tablewp_list_pluckwp_get_post_cats
引入
6.3.0
弃用
-

在区块数组中查找首次出现的特定区块。

function wp_get_first_block( $blocks, $block_name ) {
	foreach ( $blocks as $block ) {
		if ( $block_name === $block['blockName'] ) {
			return $block;
		}
		if ( ! empty( $block['innerBlocks'] ) ) {
			$found_block = wp_get_first_block( $block['innerBlocks'], $block_name );

			if ( ! empty( $found_block ) ) {
				return $found_block;
			}
		}
	}

	return array();
}

常见问题

FAQs
查看更多 >