Skip to content
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

Don't try and render unstable location if Nav block has ID #36863

Merged
merged 4 commits into from
Nov 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,15 @@ function render_block_core_navigation( $attributes, $content, $block ) {

$inner_blocks = $block->inner_blocks;

// If `__unstableLocation` is defined, create inner blocks from the classic menu assigned to that location.
if ( empty( $inner_blocks ) && array_key_exists( '__unstableLocation', $attributes ) ) {
// If `__unstableLocation` is defined and:
// - we have menu items at the defined location
// - we don't have a relationship to a `wp_navigation` Post (via `navigationMenuId`).
// ...then create inner blocks from the classic menu assigned to that location.
if (
array_key_exists( '__unstableLocation', $attributes ) &&
! array_key_exists( 'navigationMenuId', $attributes ) &&
! empty( gutenberg_get_menu_items_at_location( $attributes['__unstableLocation'] ) )
) {
$menu_items = gutenberg_get_menu_items_at_location( $attributes['__unstableLocation'] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now an inefficiency here as we are calling gutenberg_get_menu_items_at_location twice...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow up here.

if ( empty( $menu_items ) ) {
return '';
getdave marked this conversation as resolved.
Show resolved Hide resolved
Expand Down