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

Navigation: fix invalid permissions warning by avoiding using trashed wp_navigation posts (JS implementation) #42982

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ function Navigation( {
hasResolvedCanUserCreateNavigationMenu,
} = useNavigationMenu( ref );

const navMenuResolvedButMissing =
hasResolvedNavigationMenus && isNavigationMenuMissing;

// Attempt to retrieve and prioritize any existing navigation menu unless
// a specific ref is allocated or the user is explicitly creating a new menu. The aim is
// for the block to "just work" from a user perspective using existing data.
Expand Down Expand Up @@ -386,6 +389,7 @@ function Navigation( {
if ( isSelected || isInnerBlockSelected ) {
if (
ref &&
! navMenuResolvedButMissing &&
hasResolvedCanUserUpdateNavigationMenu &&
! canUserUpdateNavigationMenu
) {
Expand Down
12 changes: 7 additions & 5 deletions packages/block-library/src/navigation/use-navigation-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ function selectExistingMenu( select, ref ) {
args
);

// Trashed Navigation posts are considered invalid.
const isNavigationMenuPublished = editedNavigationMenu.status === 'publish';

return {
isNavigationMenuResolved: hasResolvedNavigationMenu,
isNavigationMenuMissing: hasResolvedNavigationMenu && ! navigationMenu,
isNavigationMenuMissing:
hasResolvedNavigationMenu &&
( ! navigationMenu || ! isNavigationMenuPublished ),

// getEditedEntityRecord will return the post regardless of status.
// Therefore if the found post is not published then we should ignore it.
navigationMenu:
editedNavigationMenu.status === 'publish'
? editedNavigationMenu
: null,
navigationMenu: isNavigationMenuPublished ? editedNavigationMenu : null,
};
}