WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 days ago

#37782 accepted defect (bug)

Duplicate Page Entry in View All Pages when generating a Menu

Reported by: garrett-eclipse Owned by: garrett-eclipse
Milestone: 5.2 Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: has-patch needs-testing
Focuses: ui, administration, privacy Cc:

Description

Hello,

Opening here for developer input. Original support topic; https://wordpress.org/support/topic/is-there-a-reason-two-homepages-show-in-menu-editor?replies=2#post-8787393

As @girlieworks mentioned on the support topic WordPress adds an extra checkbox to the top of the page list for the Page that is set as your Static Front Page when you're creating a menu.

In this list it appears as duplicate with the first being prefixed with 'Home:'.

This caused confusion initially for myself as I was setting up a small site where all pages were to be part of the navigation, so when I was building the menu I went to Pages > View All > Select All before adding, this resulting in my Homepage being in the menu twice. Easy enough to remove, but as it wasn't expected hadn't originally noticed the duplicate.

Is that behaviour correct, or should the original entry for the Home page be filtered when the Static Front Page entry is added to the list?

Thank you

Attachments (6)

37782.diff (875 bytes) - added by garrett-eclipse 4 months ago.
Suppress duplicate front_page menu item
37782.2.diff (4.6 KB) - added by garrett-eclipse 4 months ago.
Second iteration to affect posts_page and privacy_page as well
37782.4.diff (7.6 KB) - added by garrett-eclipse 4 months ago.
Update using postnot_in, and $echo on _post_status
37782.5.diff (7.9 KB) - added by garrett-eclipse 4 months ago.
Update append of _post_status after the esc_html to preserve the span
Screen Shot 2018-09-25 at 12.49.52 AM.png (56.1 KB) - added by garrett-eclipse 4 months ago.
Full Sample
37782.6.diff (8.0 KB) - added by garrett-eclipse 4 months ago.
Adding doc details to post_states functions

Download all attachments as: .zip

Change History (23)

#1 @SergeyBiryukov
2 years ago

  • Component changed from General to Menus

#3 @swissspidy
2 years ago

  • Version changed from 4.6 to 3.0

#4 @mdgl
2 years ago

I agree this is rather confusing. In my case there is no visual indication as to why the additional reference to "Home" has been added to the list of pages (because my front page is also called "Home" - see comment:11:ticket:25410). The customizer, on the other hand adds an additional reference to "Home" but this time it is identified as a custom link rather than a page link, which is at least clearer. Both of these features still persist with the "home" and "front page" confusion, however as the link being added is actually a reference to the "front page" (often the site home) rather than the WP concept of "home".

Last edited 2 years ago by mdgl (previous) (diff)

@garrett-eclipse
4 months ago

Suppress duplicate front_page menu item

#5 @garrett-eclipse
4 months ago

  • Keywords has-patch needs-testing added
  • Owner set to garrett-eclipse
  • Status changed from new to accepted

I've posted an initial loop to suppress the duplicate home entry and would appreciate your review @SergeyBiryukov

@garrett-eclipse
4 months ago

Second iteration to affect posts_page and privacy_page as well

#6 @garrett-eclipse
4 months ago

Reviewing this further I thought the implementation would benefit from expanding to include page_for_posts and wp_page_for_privacy_policy as found in _post_states(); https://github.com/WordPress/WordPress/blob/56c162fbc9867f923862f64f1b4570d885f1ff03/wp-admin/includes/template.php#L1908-L1920

Posted a new concept.

Sadly I had to create a get_post_status method instead of just using _post_states as it just echos and I needed to append. Was that the right approach? Or should I have updated it to simply use a param default $echo = true.

Also am going to revise I believe to use the posts__not_in array on the original query rather than running a foreach to unset posts.

But thoughts on current direction appreciated.

Last edited 4 months ago by SergeyBiryukov (previous) (diff)

This ticket was mentioned in Slack in #core by garrett-eclipse. View the logs.


4 months ago

@garrett-eclipse
4 months ago

Update using postnot_in, and $echo on _post_status

@garrett-eclipse
4 months ago

Update append of _post_status after the esc_html to preserve the span

#8 @garrett-eclipse
4 months ago

I've just put out another revision as [37782.5.diff]

This version uses the post__not_in argument on the WP_Query. But I had to do a check when the only pages returned are 'important' as so would be suppressed form the query making pagination fail, in this case I drop the suppress and prepend and just rely on the WP_Query results.

I've also updated the _post_status to support an $echo param.

And attached is a screen from my test environment.

Feedback and direction appreciated

Last edited 4 months ago by garrett-eclipse (previous) (diff)

@garrett-eclipse
4 months ago

Adding doc details to post_states functions

#9 @garrett-eclipse
4 months ago

  • Focuses privacy added

Added a privacy focus as it would be a small win for the Privacy team to expose the Privacy Policy page so users directed to add the page to their menu find it easily.

This ticket was mentioned in Slack in #core by garrett-eclipse. View the logs.


4 months ago

This ticket was mentioned in Slack in #core by garrett-eclipse. View the logs.


4 months ago

This ticket was mentioned in Slack in #core-privacy by garrett-eclipse. View the logs.


4 months ago

#13 @SergeyBiryukov
4 months ago

  • Milestone changed from Awaiting Review to 5.0

#14 @peterwilsoncc
3 months ago

  • Milestone changed from 5.0 to 5.1

Moving to the 5.1 milestone due to the WordPress 5.0 focus on the new editor (Gutenberg).

This ticket was mentioned in Slack in #core-privacy by desrosj. View the logs.


5 days ago

This ticket was mentioned in Slack in #core-privacy by desrosj. View the logs.


2 days ago

#17 @pento
2 days ago

  • Milestone changed from 5.1 to 5.2

This patch needs testing and review.

Note: See TracTickets for help on using tickets.