-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigation: Remove the IS_GUTENBERG_PLUGIN check around block_core_navigation_parse_blocks_from_menu_items #47824
Conversation
…vigation_parse_blocks_from_menu_items
Thank you Ben!
This file is copied to core, so if it works here it will be working there. Besides that I tested in core with your patch and no fatal is there.. |
function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) { | ||
if ( empty( $menu_items ) ) { | ||
return array(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see there are still protected functions above. Are these still Gutenberg-only functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No from what I see.
E.g. block_core_navigation_sort_menu_items_by_parent_id
is called in render_block_core_navigation
without garding defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So potentially there are remaining code paths that can lead to errors right? Or are these impossible to trigger on Core @scruffian
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the guards for both remaining functions - https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/navigation/index.php#L580-L600.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think the others are guarded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested with WP core trunk by applying the same changes and confirmed this fixes the error.
Cherry-picked this PR to the wp/6.2 branch. |
What?
As raised in #47822,
block_core_navigation_parse_blocks_from_menu_items
is now called in code paths outside of the Gutenberg plugin, so we should remove this wrapper.Why?
This is needed for the case when a classic menu is converted into a wp_navigation menu. Since we want this to happen in core now, we need to make this function available.
How?
Just move the code outside the conditional:
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {
Testing Instructions
I'm not sure. To hit the code paths you need to:
However I'm not sure how to test that the fix is working in trunk.