Automattic\WooCommerce\Internal\Utilities

BlocksUtil::flatten_blocks()public staticWC 1.0

Return blocks with their inner blocks flattened.

{} Это метод класса: BlocksUtil{}

Хуков нет.

Возвращает

Массив. All blocks.

Использование

$result = BlocksUtil::flatten_blocks( $blocks );
$blocks(массив) (обязательный)
Array of blocks as returned by parse_blocks().

Код BlocksUtil::flatten_blocks() WC 6.6.1

public static function flatten_blocks( $blocks ) {
	return array_reduce(
		$blocks,
		function( $carry, $block ) {
			array_push( $carry, array_diff_key( $block, array_flip( array( 'innerBlocks' ) ) ) );
			if ( isset( $block['innerBlocks'] ) ) {
				$inner_blocks = self::flatten_blocks( $block['innerBlocks'] );
				return array_merge( $carry, $inner_blocks );
			}

			return $carry;
		},
		array()
	);
}