block_core_navigation_get_fallback_blocks() – Retrieves the appropriate fallback to be used on the front of the site when there is no menu assigned to the Nav block.

You appear to be a bot. Output may be restricted

Description

Retrieves the appropriate fallback to be used on the front of the site when there is no menu assigned to the Nav block.

This aims to mirror how the fallback mechanic for wp_nav_menu works. See https://developer.wordpress.org/reference/functions/wp_nav_menu/#more-information.

Usage

$array = block_core_navigation_get_fallback_blocks();

Parameters

Returns

array the array of blocks to be used as a fallback.

Source

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


Lines:

1 to 43 of 43
function block_core_navigation_get_fallback_blocks() {
  $page_list_fallback = array(
    array(
      'blockName' => 'core/page-list',
      'attrs'     => array(
        '__unstableMaxPages' => 4,
      ),
    ),
  );

  $registry = WP_Block_Type_Registry::WP_Block_Type_Registry::get_instance();

  // If `core/page-list` is not registered then return empty blocks.
  $fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();

  // Default to a list of Pages.

  $navigation_post = block_core_navigation_get_first_non_empty_navigation();

  // Prefer using the first non-empty Navigation as fallback if available.
  if ( $navigation_post ) {
    $maybe_fallback = block_core_navigation_filter_out_empty_blocks( parse_blocks( $navigation_post->post_content ) );

    // Normalizing blocks may result in an empty array of blocks if they were all `null` blocks.
    // In this case default to the (Page List) fallback.
    $fallback_blocks = ! empty( $maybe_fallback ) ? $maybe_fallback : $fallback_blocks;
  }

  
/**
 * Filters the fallback experience for the Navigation block.
 *
 * Returning a falsey value will opt out of the fallback and cause the block not to render.
 * To customise the blocks provided return an array of blocks - these should be valid
 * children of the `core/navigation` block.
 *
 * @since 5.9.0
 *
 * @param array[] default fallback blocks provided by the default block mechanic.
 */
  return apply_filters( 'block_core_navigation_render_fallback', $fallback_blocks );
}
 

 View on GitHub View on Trac