_flatten_blocks() – Returns an array containing the references of the passed blocks and their inner blocks.

You appear to be a bot. Output may be restricted

Description

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

Usage

$array = _flatten_blocks( $blocks );

Parameters

$blocks
( array ) required – array of blocks.

Returns

array block references to the passed blocks and their inner blocks.

Source

File name: wordpress/wp-includes/block-template-utils.php
Lines:

1 to 21 of 21
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;
}
 

 View on GitHub View on Trac