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 link server renderer tries to get_post on links with types other than post/page causing links to not render #28712

Closed
fullofcaffeine opened this issue Feb 4, 2021 · 4 comments · Fixed by #28892
Assignees
Labels
[Block] Navigation Affects the Navigation Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Milestone

Comments

@fullofcaffeine
Copy link
Member

fullofcaffeine commented Feb 4, 2021

Description

The get_post here doesn't work with categories (and possibly other link types different from post/page?), and (might) end up returning an empty string, resulting in the inner link block not rendering in the frontend.

It seems that this went unnoticed because, in a testing environment (i.e when testing manually using a fresh WP org install), the IDs of post/pages and categories are small enough that they overlap, and that ends causing the link to be rendered, causing the false impression it's working as expected.

Step-by-step reproduction instructions

  1. Add a new post or page. We're also assuming there's a post with ID = 1 in your WP instance already; you'll also use the default "Uncategorized" cat (which also has 1 as the ID);
  2. Add a horizontal or vertical Navigation block to the page. Add any number of links you'd like, but be sure to add at least one of type "Category" and select the "Uncategorized" cat;
  3. View the published page. You'll see that the navigation link for "Uncategorized" is shown;
  4. Now edit the post with ID = 1 and set it to private;
  5. Go back to and view the test post/page you created earlier. You'll see that the nav link for "Uncategorized" is now gone!

Expected behavior

I expect any navigation links with a type other than page or post to not be influenced by settings from posts / pages and to show as expected.

Actual behavior

Navigation links with type other than page / post are not rendered if there's not a post/page with the same ID and or if there is and it's private.

Screenshots or screen recording (optional)

categorypostidoverlap.mp4

WordPress information

  • WordPress version:
  • Gutenberg version: 9.8.3 and master (537412fd43)
  • Are all plugins except Gutenberg deactivated? Yes.
  • Are you using a default theme (e.g. Twenty Twenty-One)? Yes.

Device information

  • Device: Desktop.
  • Operating system: Ubuntu Linux 18.04.
  • Browser: Firefox 86.0b5 (64-bit).
@fullofcaffeine fullofcaffeine changed the title Navigation link server rendered tries to get_post on links with types other than post/page causing links to not render Navigation link server renderer tries to get_post on links with types other than post/page causing links to not render Feb 4, 2021
@talldan talldan added [Block] Navigation Affects the Navigation Block [Type] Bug An existing feature does not function as intended labels Feb 4, 2021
@sirreal sirreal added this to the Gutenberg 9.9 milestone Feb 4, 2021
@sirreal sirreal added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Feb 4, 2021
@sirreal sirreal modified the milestones: Gutenberg 9.9, Gutenberg 9.8 Feb 4, 2021
@ockham
Copy link
Contributor

ockham commented Feb 4, 2021

@draganescu @talldan Could y'all look into this one? Seems like it'd be good to get it fixed for GB 9.9 (and by extension, WP 5.7), since it can break the nav block apparently quite badly.

@ockham
Copy link
Contributor

ockham commented Feb 4, 2021

Let's also add some test coverage (e.g. PHP unit test for render_block_core_navigation_link) when we fix this, to avoid regressions 🙂

@gwwar
Copy link
Contributor

gwwar commented Feb 9, 2021

I can try taking a look 👍 Let me know if folks already have a patch, I can help review otherwise

@gwwar gwwar self-assigned this Feb 9, 2021
@draganescu
Copy link
Contributor

Just saw this, I wont be able to work on it for this week. If it's still up next week I can come back to it, otherwise, thank you in advance, @gwwar ! :)

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 [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants