block_core_navigation_filter_out_empty_blocks() – Filter out empty "null" blocks from the block list.

You appear to be a bot. Output may be restricted

Description

Filter out empty "null" blocks from the block list.

'parse_blocks' includes a null block with '\n\n' as the content when it encounters whitespace. This is not a bug but rather how the parser is designed.

Usage

$array = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );

Parameters

$parsed_blocks
( array ) required – the parsed blocks to be normalized.

Returns

array the normalized parsed blocks.

Source

File name: wordpress/wp-includes/blocks/navigation.php
Lines:

1 to 11 of 11
function block_core_navigation_filter_out_empty_blocks( $parsed_blocks ) {
  $filtered = array_filter(
    $parsed_blocks,
    function( $block ) {
      return isset( $block['blockName'] );
    }
  );

  // Reset keys.
  return array_values( $filtered );
}
 

 View on GitHub View on Trac