Repository navigation
Navigation: fix deprecated function call in get_inner_blocks_from_unstable_location. - #77445
saratheonline wants to merge 1 commit into
Conversation
…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 .
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
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.
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. |
|
👋 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. |
|
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! |
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()
WP_Navigation_Fallback::parse_blocks_from_menu_items()
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.phpintroduced whenblock_core_navigation_get_inner_blocks_from_unstable_location()was added in 6.5.0.Why?
block_core_navigation_get_inner_blocks_from_unstable_location()(added 6.5.0) was callingblock_core_navigation_parse_blocks_from_menu_items()which was deprecated in 6.3.0. On any site using aNavigation block with the
__unstableLocationattribute (classic menu location fallback), this triggered a_deprecated_function()notice on every page render whenWP_DEBUGis enabled.The deprecated function's
@deprecateddocblock referencedWP_Navigation_Fallback::parse_blocks_from_menu_items()as the replacement, but that method does not exist. The correct replacement in Core isWP_Classic_To_Block_Menu_Converter::to_blocks().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), the0key is absent and PHP8.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?
block_core_navigation_convert_menu_items_to_blocks(). Its recursive calls reference itself rather than the deprecated wrapper, so the deprecationnotice no longer fires once per submenu level.
block_core_navigation_get_inner_blocks_from_unstable_location()to call the helper directly with the?? array()guard.block_core_navigation_parse_blocks_from_menu_items()to a thin shim: fires_deprecated_function()once, then delegates to the helper. Corrected its@deprecateddocblock to referenceWP_Classic_To_Block_Menu_Converter::to_blocks().Testing Instructions
__unstableLocation(the classic menu location fallback).WP_DEBUGandWP_DEBUG_LOGinwp-config.php.wp-content/debug.log.Before this fix: a
_deprecated_functionnotice forblock_core_navigation_parse_blocks_from_menu_itemsappears — 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.