WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 12 days ago

Last modified 12 days ago

#39758 closed defect (bug) (fixed)

menu-item-home does not get class current-menu-item (not consistent with live page)

Reported by: Liddika Owned by: adamsilverstein
Milestone: 4.8 Priority: normal
Severity: normal Version: 4.7
Component: Customize Keywords: needs-testing has-patch
Focuses: Cc:

Description

When inside of the customizer, and the navigation menu has a home menu item, and the user is on the home page, that menu item will not get tagged with the class current-menu-item nor current_page_item inside of <li>.

This is not consistent with the live page of the navigation menu. The live page does include both current-menu-item and current_page_item when being on the home page.

Home menu item on live page:

<li id="menu-item-2" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-2"><a href="http://example.com/">Home</a></li>

Home menu item in customizer:

<li id="menu-item-2" class="menu-item menu-item-type-custom menu-item-object-custom  menu-item-home menu-item-2"><a href="http://example.com/">Home</a></li>

As you can see, current-menu-item current_page_item are missing in the customizer.

Attachments (3)

39758.diff (905 bytes) - added by adamsilverstein 4 months ago.
39758.patch (944 bytes) - added by priyankabehera155 7 weeks ago.
39758.2.patch (1.0 KB) - added by priyankabehera155 6 weeks ago.

Download all attachments as: .zip

Change History (24)

#1 @adamsilverstein
4 months ago

@Liddika Thanks for the bug report.

I tried to reproduce this issue and I actually see the current-menu-item class added to the homepage menu item when I have the homepage set to a specific page. I don't see the current_page_item class in the customizer however.

Can you please try to reproduce with a bundled theme, and also provide some additional details about your settings - do you have the homepage set to a static page or your latest posts? What does your menu item link to exactly, is it a custom link?

Here are some screenshots of what I see -

Front end:
https://cl.ly/1v3w2c0g1k0D/wpdev__Just_another_WordPress_site_2017-02-01_09-03-16.jpg

Customizer:
https://cl.ly/3N0u0n3J2x2P/Customize_wpdev__Just_another_WordPress_site_2017-02-01_09-05-39.jpg

#2 @adamsilverstein
4 months ago

  • Keywords has-patch reporter-feedback added
  • Milestone changed from Awaiting Review to 4.8
  • Owner set to adamsilverstein
  • Status changed from new to assigned
  • Version changed from 4.7.2 to 4.7

In 39758.diff:

Nav Menus: Fix an issue with menu classes in the customizer.

Remove query vars when comparing menu urls with current url to determine correct menu item classes.

In the customizer, menu items now contain a changeset uuid as part of their url string, eg http://wpdev.localhost/?customize_changeset_uuid=ddc1fa2e-e347-4042-8f1c-f5ac470839e0&customize_theme=twentyseventeen&customize_messenger_channel=preview-0. The code in nav-menu-template.php wasn't working because these urls didn't match the comparison urls without the query vars, breaking applied classes in several cases. This patch strips the query var off the url before entering the comparison block and fixes the case raised on the ticket.

cc: @westonruter

@Liddika can you please give this patch a test and test if it resolves the issue you were seeing? Thanks.

#3 @westonruter
4 months ago

  • Keywords needs-testing added; reporter-feedback removed
  • Milestone changed from 4.8 to 4.7.3

Good catch! Seems that this should be milestoned for 4.7.3

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


4 months ago

#5 @jbpaul17
4 months ago

@Liddika any results from your testing of the 39758.diff patch and whether it resolves the issue you were seeing?

#6 @westonruter
3 months ago

  • Milestone changed from 4.7.3 to 4.7.4

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


2 months ago

#8 @jipmoors
2 months ago

  • Keywords needs-patch added; has-patch removed

The fix is breaking functionality in the specific situation when the permalinks are set to the default 'plain' setting.

Testing variables

  • p=1 > set as static home page
  • p=2 > normal page
  • permalink structure: 'plain'
  • have a 'Home' menu item
  • have the normal page as menu item

When a page other than the Home page is loaded, the Home link is also receiving the 'current-menu-item' and 'current_page_item' classes.

Whenever the permalink structure is including a '?' the relative root cannot be determined because the entire permalink match should be taken into consideration to have a certain request identification.

This ticket was mentioned in Slack in #core by swissspidy. View the logs.


2 months ago

#10 @priyankabehera155
7 weeks ago

  • Keywords has-patch added; needs-patch removed

Hi @westonruter, @jipmoors ,

I have added a patch which will check if that is customize page then it will replace the relative root variable.
I have also checked the patch in breaking functionality provided by @jipmoors. It is working perfectly fine.

This ticket was mentioned in Slack in #core-customize by priyankabehera. View the logs.


7 weeks ago

This ticket was mentioned in Slack in #core by priyankabehera. View the logs.


7 weeks ago

#13 @adamsilverstein
6 weeks ago

  • Keywords needs-refresh added

Hi @priyankabehera155 thanks for your patch!

This seems like a good solution, thanks also for checking that it also resolves @jipmoors issue (and @jipmoors, thanks for catching that!). Can you please refresh the patch with tabs instead of spaces and also maybe add a comment line above the conditional explaining why the code is there? Thanks!

#14 @priyankabehera155
6 weeks ago

  • Keywords needs-refresh removed

Hi @adamsilverstein,

Thank you for your points.
I have added a short comment which describes the code and the coding standard tab instead of space. Thanks!

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


6 weeks ago

#16 @swissspidy
6 weeks ago

@adamsilverstein Have you already had a chance to test the latest patch?

#17 @swissspidy
6 weeks ago

  • Milestone changed from 4.7.4 to 4.7.5

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


2 weeks ago

#19 @desrosj
2 weeks ago

  • Milestone changed from 4.7.5 to 4.8

#20 @adamsilverstein
12 days ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 40658:

Customizer: Fix an issue with menu classes in the customizer preview.

In customizer preview, strip changeset uuid in menu urls before comparing with current url to determine menu item classes.

In the customizer, menu items now contain a changeset uuid as part of their urls. Strip the changeset uuid off the url before comparing with current url (which lacks the changeset uuid).

Props priyankabehera155, jipmoors.
Fixes #39758.

#21 @adamsilverstein
12 days ago

@westonruter should we reopen this for backporting to 4.7.x?

Note: See TracTickets for help on using tickets.