Make WordPress Core

Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#51869 closed defect (bug) (duplicate)

float values for menu positions overwriting each other

Reported by: pomegranate Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.8
Component: Administration Keywords:
Focuses: administration Cc:


When using add_menu_page() and setting the $position argument with a float (say, 57.77) this will overwrite other menu items with either 57 (int) for $position or 57.# (any float). All of them end up at the 57(int) key. This is despite the check for duplicates. Using '57.7' (string) instead will not have this issue.


Floats are also cast to ints, which means that the fractional part will be truncated. E.g. the key 8.7 will actually be stored under 8.

The effect is that menu items disappear/get overwritten.

Here's a simple example to demonstrate the bug:

add_action( 'admin_menu', function(){
                __( 'Heinz Ketchup', 'heinz-ketchup' ),
                __( 'Heinz Ketchup', 'heinz-ketchup' ),
                __( 'Home Made Ketchup', 'home-made-ketchup' ),
                __( 'Home Made Ketchup', 'home-made-ketchup' ),
} );

Only the second menu item will be shown. I believe this is undesired behavior.
The solution would be to cast any float value to a string before setting it as a key in the menu array.

Change History (2)

#1 @SergeyBiryukov
13 months ago

  • Component changed from Menus to Administration
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac! Thanks for the report.

Just noting that I was able to reproduce the issue. Looks like we're already tracking it in #40927.

Moving to the Administration component, as Menus is specifically for the Menus screen and nav menu functions.

#2 @hellofromTonya
13 months ago

  • Version changed from 5.6 to 4.8

Changing the Version to match version reported #40927.

Note: See TracTickets for help on using tickets.