Skip to content

Navigation: fix deprecated function call in get_inner_blocks_from_unstable_location. - #77445

Open
saratheonline wants to merge 1 commit into
WordPress:trunkfrom
saratheonline:fix/navigation-unstable-location-deprecated-call
Open

saratheonline wants to merge 1 commit into
WordPress:trunkfrom
saratheonline:fix/navigation-unstable-location-deprecated-call

Conversation

@saratheonline

Copy link
Copy Markdown
  • Replace call to deprecated block_core_navigation_parse_blocks_from_menu_items()
    with a new private helper block_core_navigation_convert_menu_items_to_blocks()

    • Add missing null-coalescing guard on $menu_items_by_parent_id[0]
    • Fix incorrect @deprecated docblock referencing non-existent
      WP_Navigation_Fallback::parse_blocks_from_menu_items()
    • As a bonus, recursive calls inside the helper no longer fire the deprecation
      notice on every submenu level.

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

    What?

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

    Fixes three bugs in packages/block-library/src/navigation/index.php introduced when block_core_navigation_get_inner_blocks_from_unstable_location() was added in 6.5.0.

    Why?

    1. block_core_navigation_get_inner_blocks_from_unstable_location() (added 6.5.0) was calling block_core_navigation_parse_blocks_from_menu_items() which was deprecated in 6.3.0. On any site using a
      Navigation block with the __unstableLocation attribute (classic menu location fallback), this triggered a _deprecated_function() notice on every page render when WP_DEBUG is enabled.

    2. The deprecated function's @deprecated docblock referenced WP_Navigation_Fallback::parse_blocks_from_menu_items() as the replacement, but that method does not exist. The correct replacement in Core is
      WP_Classic_To_Block_Menu_Converter::to_blocks().

    3. The same call site accessed $menu_items_by_parent_id[0] directly without a ?? array() guard. If all menu items carry a non-zero parent ID (e.g. due to data corruption), the 0 key is absent and PHP
      8.x raises an undefined array key notice. The equivalent call in the already-deprecated block_core_navigation_get_classic_menu_fallback_blocks() correctly used ?? array().

    How?

    • Extracted the conversion logic into a new private helper block_core_navigation_convert_menu_items_to_blocks(). Its recursive calls reference itself rather than the deprecated wrapper, so the deprecation
      notice no longer fires once per submenu level.
    • Updated block_core_navigation_get_inner_blocks_from_unstable_location() to call the helper directly with the ?? array() guard.
    • Reduced block_core_navigation_parse_blocks_from_menu_items() to a thin shim: fires _deprecated_function() once, then delegates to the helper. Corrected its @deprecated docblock to reference
      WP_Classic_To_Block_Menu_Converter::to_blocks().

    Testing Instructions

    1. Set up a classic WordPress theme that registers a nav menu location.
    2. Assign a classic menu to that location via Appearance → Menus, including at least one item with sub-items.
    3. Add a Navigation block to a page/template and configure it to use __unstableLocation (the classic menu location fallback).
    4. Enable WP_DEBUG and WP_DEBUG_LOG in wp-config.php.
    5. Load a front-end page that renders the Navigation block.
    6. Check wp-content/debug.log.

    Before this fix: a _deprecated_function notice for block_core_navigation_parse_blocks_from_menu_items appears — once per submenu level per request.
    After this fix: no deprecation notices appear; the Navigation block renders identically.

    Testing Instructions for Keyboard

    No UI changes — this is a PHP-only fix. Keyboard behaviour of the Navigation block is unaffected.

    Use of AI Tools

    This PR was authored with the assistance of Claude (Anthropic) for code analysis and implementation. The changes have been reviewed and verified manually.

…table_location. Fixes WordPress#77442

- Replace call to deprecated block_core_navigation_parse_blocks_from_menu_items() with a new private helper block_core_navigation_convert_menu_items_to_blocks() 
- Add missing null-coalescing guard on \$menu_items_by_parent_id[0]                                                                                      
- Fix incorrect @deprecated docblock referencing non-existent WP_Navigation_Fallback::parse_blocks_from_menu_items()                                                                                                                                                  
- As a bonus, recursive calls inside the helper no longer fire the deprecation notice on every submenu level .
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: saratheonline <saratheonline@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

@github-actions github-actions Bot added [Package] Block library /packages/block-library First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository labels Apr 17, 2026
@github-actions

Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @saratheonline! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@saratheonline

Copy link
Copy Markdown
Author

Could a maintainer please add the [Type] Bug label? This PR is a bug fix and I don't have the permissions to add labels. Thanks!

@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Block] Navigation Affects the Navigation Block labels Apr 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Affects the Navigation Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants