WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 5 weeks ago

#36212 accepted defect (bug)

Empty menu items are deleted without warning

Reported by: cameronjonesweb Owned by: audrasjb
Milestone: 5.5 Priority: normal
Severity: normal Version:
Component: Menus Keywords: has-patch needs-testing
Focuses: ui, administration Cc:

Description

I recently discovered that menu items with with an empty label are deleted from the menu upon save without any warning or notice. The particular situation was that I was adding a menu with an icon font for the items, so the labels were empty but had classes. Obviously a HTML comment can be used in this instance, but there should be some way to either communicate with the user that items with an empty label will be removed, disable saving of a menu with empty labels, or some way to handle empty labels without deleting the item.

Attachments (7)

36212.diff (715 bytes) - added by farookibrahim 3 years ago.
6ce75a0d8883e74384a12eb87c1a2304.gif (433.9 KB) - added by audrasjb 3 months ago.
Before the patch: blank menu item removed
c58d1de87b52fe7e5faea0375d5bb2d9.gif (346.1 KB) - added by audrasjb 3 months ago.
After the patch: blank menu item remains but its label is not blank anymore
36212.patch (2.2 KB) - added by samful 5 weeks ago.
admin-view-menu-editor-with-no-titles.png (16.2 KB) - added by samful 5 weeks ago.
front-end-menu-with-symbols-in-empty-menu-items.png (36.1 KB) - added by samful 5 weeks ago.
36212.2.diff (2.8 KB) - added by samful 11 days ago.
refeshed with correct src/ path and got rid of some unused variables

Download all attachments as: .zip

Change History (14)

#1 @obenland
4 years ago

  • Version trunk deleted

#2 @welcher
4 years ago

  • Keywords needs-patch added

Thanks for contributing to core! Would you like to propose a solution with a patch?

@farookibrahim
3 years ago

#3 @farookibrahim
3 years ago

  • Keywords has-patch added; needs-patch removed

#4 @audrasjb
17 months ago

  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to Future Release
  • Owner set to audrasjb
  • Status changed from new to accepted

The patch doesn't applies cleanly anymore. Will need a refresh.

Moving to Future Realse as the solution proposed in the patch looks fine on my side.

#5 @audrasjb
3 months ago

  • Milestone changed from Future Release to 5.5

@audrasjb
3 months ago

Before the patch: blank menu item removed

@audrasjb
3 months ago

After the patch: blank menu item remains but its label is not blank anymore

#6 @audrasjb
3 months ago

The proposed patch (needs refresh) works partially. The menu item remains, but its title is not blank, it takes the object’s original title. I think it will also need to make some changes in wp_setup_nav_menu_item in wp-includes/nav-menu.php.

#7 @samful
5 weeks ago

  • Keywords needs-testing added; needs-refresh removed

@audrasjb had the right advice here, so thanks for pointing me in the right direction. This patch should solve the issue you were having.

In my testing, the patch seemed to work perfectly, but I also want to note that after testing, I found that the theme "Twenty Nineteen" (My other installed themes had no issues) has a CSS rule which hides any empty <a> tags. So, to get round this I made a quick CSS rule to display empty <a> elements again just for Twenty Nineteen. You may want to include this in your custom css if you are using Twenty Nineteen, or edit it to something similar if using another theme that hides empty <a> elements:

.main-navigation .sub-menu > li > a:empty{
	display: block;
}

I then went on to test what @cameronjonesweb was initially trying to do (put an icon font or a symbol in the menu item):

.main-navigation .sub-menu > li > a:empty:after {
	content: "\00a9";
}

I'll also attach screenshots of the admin view where I edited the menu items and the front end where the empty items have the copyright symbol \00a9. This is just an example of how it can be done using the current patch and the CSS above on the "Twenty Nineteen" theme.

If someone else could give this patch a test too, that would be very helpful :)

@samful
5 weeks ago

@samful
11 days ago

refeshed with correct src/ path and got rid of some unused variables

Note: See TracTickets for help on using tickets.