WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#16724 closed enhancement (duplicate)

Add current-menu-item to custom links that only contains path

Reported by: chrisjean Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: has-patch
Focuses: Cc:

Description

It is possible to add a custom link to a menu with a URL that only contains a path, such as "/contact". The link will work properly, but the menu item will not receive the current-menu-item class when that page is active.

The supplied patch (current-menu-item-custom-link-path.diff) allows the current-menu-item class to be applied to the path-only custom links by prepending the current request's scheme and domain to the link, turning it into a complete URL, before running the check.

The patch considers a link as an incomplete URL if it begins with a forward-slash (/). This way, complete URLs (which will always begin with a letter from the scheme) will be unmodified.

Attachments (1)

current-menu-item-custom-link-path.diff (1.1 KB) - added by chrisbliss18 3 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 nacin3 years ago

Note that this would break scheme-agnostic //-style links.

Last edited 3 years ago by nacin (previous) (diff)

comment:2 nacin3 years ago

  • Type changed from defect (bug) to enhancement
  • Version changed from 3.1 to 3.0

comment:3 chrisbliss183 years ago

If you are talking about having links to network locations such as //host/path, I'm not sure that needs to be a concern.

This section of code and the $item_url variable being modified are only for determining the classes to attribute to the different menu elements. So, even if there is an off chance that such a link could be improperly gain the current-menu-item class, this will do nothing to affect functionality.

I tested by adding a custom link with a URL of //contact (since I have a page at /contact). I then navigated to the contact page and found that the contact page menu item had the current-menu-item class as expected and that the //contact menu item did not have this class. This is because the //contact link is being changed to http://domain/other-path//contact which will not match http://domain/other-path/contact.

Even if someone navigates to http://domain/other-path//contact manually, the redirect_canonical function takes care of redirecting to http://domain/other-path/contact/ so that even this will fail to add the current-menu-item class to the //contact link.

Is there some angle that I haven't account for that will still cause an issue?

comment:4 jamescollins3 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

This looks like a duplicate of #15954.

comment:5 SergeyBiryukov3 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.