block_core_navigation_get_fallback_blocks

The timeline below displays how wordpress function block_core_navigation_get_fallback_blocks has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.5

/**
 * 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.
 *
 * @return array the array of blocks to be used as a fallback.
 */
function block_core_navigation_get_fallback_blocks()
{
    $page_list_fallback = array(array('blockName' => 'core/page-list', 'innerContent' => array(), 'attrs' => array()));
    $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();
    $navigation_post = WP_Navigation_Fallback::get_fallback();
    // Use the first non-empty Navigation as fallback if available.
    if ($navigation_post) {
        $parsed_blocks = parse_blocks($navigation_post->post_content);
        $maybe_fallback = block_core_navigation_filter_out_empty_blocks($parsed_blocks);
        // 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;
        if (function_exists('set_ignored_hooked_blocks_metadata')) {
            // Run Block Hooks algorithm to inject hooked blocks.
            // We have to run it here because we need the post ID of the Navigation block to track ignored hooked blocks.
            $markup = block_core_navigation_insert_hooked_blocks($fallback_blocks, $navigation_post);
            $blocks = parse_blocks($markup);
            if (isset($blocks[0]['innerBlocks'])) {
                $fallback_blocks = $blocks[0]['innerBlocks'];
            }
        }
    }
    /**
     * 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[] $fallback_blocks default fallback blocks provided by the default block mechanic.
     */
    return apply_filters('block_core_navigation_render_fallback', $fallback_blocks);
}

WordPress Version: 6.3

/**
 * 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.
 *
 * @return array the array of blocks to be used as a fallback.
 */
function block_core_navigation_get_fallback_blocks()
{
    $page_list_fallback = array(array('blockName' => 'core/page-list'));
    $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();
    if (class_exists('WP_Navigation_Fallback')) {
        $navigation_post = WP_Navigation_Fallback::get_fallback();
    } else {
        $navigation_post = Gutenberg_Navigation_Fallback::get_fallback();
    }
    // Use the first non-empty Navigation as fallback if available.
    if ($navigation_post) {
        $parsed_blocks = parse_blocks($navigation_post->post_content);
        $maybe_fallback = block_core_navigation_filter_out_empty_blocks($parsed_blocks);
        // 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);
}

WordPress Version: 6.2

/**
 * 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.
 *
 * @return array the array of blocks to be used as a fallback.
 */
function block_core_navigation_get_fallback_blocks()
{
    $page_list_fallback = array(array('blockName' => 'core/page-list'));
    $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_most_recently_published_navigation();
    // If there are no navigation posts then try to find a classic menu
    // and convert it into a block based navigation menu.
    if (!$navigation_post) {
        $navigation_post = block_core_navigation_maybe_use_classic_menu_fallback();
    }
    // Use the first non-empty Navigation as fallback if available.
    if ($navigation_post) {
        $parsed_blocks = parse_blocks($navigation_post->post_content);
        $maybe_fallback = block_core_navigation_filter_out_empty_blocks($parsed_blocks);
        // 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);
}

WordPress Version: 6.1

/**
 * 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.
 *
 * @return array the array of blocks to be used as a fallback.
 */
function block_core_navigation_get_fallback_blocks()
{
    $page_list_fallback = array(array('blockName' => 'core/page-list'));
    $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_most_recently_published_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);
}

WordPress Version: 5.9

/**
 * 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.
 *
 * @return array the array of blocks to be used as a fallback.
 */
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::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.
     *
     * @param array[] default fallback blocks provided by the default block mechanic.
     */
    return apply_filters('block_core_navigation_render_fallback', $fallback_blocks);
}