wpseek.com
A WordPress-centric search engine for devs and theme authors



_flatten_blocks › WordPress Function

Since5.9.0
Deprecatedn/a
_flatten_blocks ( $blocks )
Access:
  • private
Parameters:
  • (array) $blocks array of blocks.
    Required: Yes
Returns:
  • (array) block references to the passed blocks and their inner blocks.
Defined at:
Codex:

Returns an array containing the references of the passed blocks and their inner blocks.



Source

function _flatten_blocks( &$blocks ) {
	$all_blocks = array();
	$queue      = array();
	foreach ( $blocks as &$block ) {
		$queue[] = &$block;
	}

	while ( count( $queue ) > 0 ) {
		$block = &$queue[0];
		array_shift( $queue );
		$all_blocks[] = &$block;

		if ( ! empty( $block['innerBlocks'] ) ) {
			foreach ( $block['innerBlocks'] as &$inner_block ) {
				$queue[] = &$inner_block;
			}
		}
	}

	return $all_blocks;
}