-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Allow private pages to display in Nav block on front of site #49223
base: trunk
Are you sure you want to change the base?
Conversation
cc @Chrico who raised the original Issue. |
Flaky tests detected in c60b763. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4489008590
|
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.
The code looks good and does what it says.
My concern is that this could potentially change the front end of sites which already have a link to a private post/page in them. Do you think that's something to be careful about?
100%. If this lands then we need to communicate the change. Do you have any ideas about how we could do that? |
To make sure I follow, is this the scenario that would be changed?
|
public static function wpTearDownAfterClass() { | ||
foreach ( self::$pages as $page_to_delete ) { | ||
wp_delete_post( $page_to_delete->ID ); | ||
} | ||
foreach ( self::$terms as $term_to_delete ) { | ||
wp_delete_term( $term_to_delete->term_id, $term_to_delete->taxonomy ); | ||
} | ||
} |
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.
This can be removed as the test class is inherting from the base WP test class which does this clean up.
See:
- https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#shared-fixtures
- https://core.trac.wordpress.org/browser/trunk/tests/phpunit/includes/abstract-testcase.php#L91
- https://github.com/WordPress/wordpress-develop/blob/95826a28f17bda68092926bb6c33a05cc9459964/tests/phpunit/includes/functions.php#L110
Correct. It's consistent with Classic Menus system but it's not how Block menus have behaved until this PR. |
I'm not sure if the old behavior (classic themes) was a feature, or a bug. It sounds to me like what classic themes were doing, was just wrong, and the block fixed the issue. |
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'm not sure if the old behavior (classic themes) was a feature, or a bug. It sounds to me like what classic themes were doing, was just wrong, and the block fixed the issue.
I was thinking more about this and I agree with this. In the same way that we'd like page slugs to update when the page updates, I think this is actually a feature not a bug. IMO we should close this.
I'm happy to close it. It did seem strange even though that's how @talldan said Classic Menus behave. I'll close this out and at least we have a paper trail to follow if it's ever raised in future. |
I double checked and it is how they work. 🤷 I didn't and still don't think it's how the nav block should work. |
There still is the need to provide to the use case where you have content which is accessible only to logged in users but logged out users should still see the link. This thing of "private pages should not appear in nav" is similar to Google not linking to Gmail just because you're logged out. Which of course is not true. Links are there pointing to things so users know things exist. |
Why not just adding a filter and let the developer decide which "post_status" should be allowed to see in "Navigation"-Block? |
Does it not work if the user adds the menu items as custom links instead of selecting the post from a dropdown? 🤔 I think that method should work and cover the scenario described above... |
@Chrico I think the filter is "yet another filter", seems like too powerful a solution for such a corner case. From the issue the problem is a disconnect between the editor and the front end of the site. I don't think the logic to not render a link that appears in the navigation block in the editor because it is private makes sense. Particularly when, as the issue describes, the page is made private after it was added to the editor. I have doubts about draft pages as well, but private pages/posts are even worse. In #27207 I did mention that draft page/post links should show some kind of "indicator that the link will not be visible on the front end". If that indicator were to exist I think things would become clearer, but I would still have doubts, but at least we could explain what is going on. For now though, as a user, having a link in my navigation not render because I made the page or post private is unexpected and impossible to figure out. I don't agree much with the idea to use "custom links", because, as a user, not finding things is super frustrating. For instance, I have a page which I linked to in my footer. In the mean time I made the page private and want to link to it in the header. I do the exact same actions and the page is not found - because I made it private, but how can I know that? I can't. Also a user that wants to link to their private page will never ever discover that they need to open the inserter and choose custom link. It's one thing to be smart like having dynamic links which update when the slugs change, and it's another to not render things based on strict heuristics, which we may not be even right about. On another note, I also don't think it's good to encourage "leftover content" in the editor, whicih is there, is visible but does not render. Users should assume that what they see in the editor renders. Hidden content, should exist via special blocks (like annotations or editorial todos etc). |
I just proposed a filter to find a middle ground between "we don't want to change", but still allow developers to change it on their own. Overall the restriction to "only post_status === Why? Because when inserting a new Navigation Item, you can search via LinkControl on So stripping off [3], what before can be allowed, is quiet frustating for the User who manages the navigation menue(s). |
That's a good point. There is an indicator for draft posts: Something similar should at least exist for private pages when they're hidden. |
What?
Allows private Posts to display in the Nav block if they are part of a menu.
Closes #33215
Why?
In the Classic Menus system it was not possible to add Private posts to a menu from the Menus screen. However, if the Post was added to a Menu and then subsequently made
Private
it would render on the front of the site and remain in the Menu on the Menus screen.The Nav Link/Submenu blocks were not mirroring this behaviour. This PR fixes things to display the same behaviour as for Classic Menus.
How?
There were two tasks that needed to be addressed.
I checked by:
publish
status only.This PR implements this part by adding
private
to the list of post statuses that are allowed.Note: it should not be possible to find/add a private post to a menu from the Link UI. That part has not changed.
Testing Instructions
Private
.Publish
status).Private
again.Testing Instructions for Keyboard
Screenshots or screencast