Skip to content

Navigation block: block_core_navigation_get_inner_blocks_from_unstable_location() calls deprecated function and lacks null-coalescing guard #77442

Open

Description

@saratheonline

Description

Three related bugs exist in packages/block-library/src/navigation/index.php:

  1. block_core_navigation_get_inner_blocks_from_unstable_location() (added 6.5.0) calls block_core_navigation_parse_blocks_from_menu_items() which was deprecated in 6.3.0. This triggers a _deprecated_function() notice on every page render when the Navigation block uses the __unstableLocation attribute (classic menu location fallback) and WP_DEBUG is enabled.
  2. The deprecated function's docblock references a non-existent replacement: WP_Navigation_Fallback::parse_blocks_from_menu_items(). That method does not exist. The actual replacement is WP_Classic_To_Block_Menu_Converter::to_blocks().
  3. Missing null-coalescing fallback: Line 1088 accesses $menu_items_by_parent_id[0] directly without ?? array(). The equivalent call inside the already-deprecated block_core_navigation_get_classic_menu_fallback_blocks() (line 1726) correctly guards this access. If all menu items carry a non-zero parent ID, the 0 key is absent and PHP 8.x raises an undefined array key notice.

Step-by-step reproduction instructions

  1. Enable WP_DEBUG and WP_DEBUG_LOG in wp-config.php.
  2. Create a Navigation block that uses a classic menu via the __unstableLocation attribute (a theme location fallback menu).
  3. Load any front-end page that renders the Navigation block.
  4. Check the debug log.

Expected: No deprecation notices.
Actual: _deprecated_function notice for block_core_navigation_parse_blocks_from_menu_items fires on every request.

Screenshots, screen recording, code snippet

`// packages/block-library/src/navigation/index.php

// Line 1088 — calls deprecated function, missing ?? array() guard:
function block_core_navigation_get_inner_blocks_from_unstable_location( $attributes ) {
$menu_items = block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] );
if ( empty( $menu_items ) ) {
return new WP_Block_List( array(), $attributes );
}
$menu_items_by_parent_id = block_core_navigation_sort_menu_items_by_parent_id( $menu_items );
$parsed_blocks = block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[0], $menu_items_by_parent_id ); // ← deprecated call + missing ?? array()
return new WP_Block_List( $parsed_blocks, $attributes );
}

// Line 1591 — incorrect @deprecated docblock:
// @deprecated 6.3.0 Use WP_Navigation_Fallback::parse_blocks_from_menu_items() instead.
// WP_Navigation_Fallback has no such method. The actual replacement is:
// WP_Classic_To_Block_Menu_Converter::to_blocks()

// Line 1726 — correct guard used in the already-deprecated sibling function:
$inner_blocks = block_core_navigation_parse_blocks_from_menu_items(
$menu_items_by_parent_id[0] ?? array(), // ← correct pattern
$menu_items_by_parent_id
);`

Proposed fix:
function block_core_navigation_get_inner_blocks_from_unstable_location( $attributes ) { $menu_items = block_core_navigation_get_menu_items_at_location( $attributes['__unstableLocation'] ); if ( empty( $menu_items ) ) { return new WP_Block_List( array(), $attributes ); } $menu_items_by_parent_id = block_core_navigation_sort_menu_items_by_parent_id( $menu_items ); $parsed_blocks = WP_Classic_To_Block_Menu_Converter::to_blocks( $menu_items_by_parent_id[0] ?? array(), $menu_items_by_parent_id ); return new WP_Block_List( $parsed_blocks, $attributes ); }

Also correct the @deprecated docblock at line 1591:
`- * @deprecated 6.3.0 Use WP_Navigation_Fallback::parse_blocks_from_menu_items() instead.

    • @deprecated 6.3.0 Use WP_Classic_To_Block_Menu_Converter::to_blocks() instead.`

Note: WP_Classic_To_Block_Menu_Converter::to_blocks() and ::group_by_parent_id() are currently private — they may need to be made public, or a new public static wrapper added.

Environment info

  • WordPress version: N/A (bug is in Gutenberg source, confirmed in trunk)
  • Gutenberg version: trunk (confirmed in packages/block-library/src/navigation/index.php)
  • Affects any site using a Navigation block with the __unstableLocation attribute
  • PHP 8.x required to surface the undefined array key notice (Issue 3)

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Activity

  1. added a commit that references this issue on Apr 17, 2026
    19f73b2
  2. added
    [Type] Code QualityIssues or PRs that relate to code quality
    and removed
    [Type] BugAn existing feature does not function as intended
    on Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions