[wp-trac] [WordPress Trac] #40927: Passing a float as the position in add_menu_page can override other menu items

WordPress Trac noreply at wordpress.org
Mon Jun 5 23:26:22 UTC 2017


#40927: Passing a float as the position in add_menu_page can override other menu
items
----------------------------+-----------------------------
 Reporter:  justinbusa      |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Menus           |    Version:  trunk
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 If you pass a float value for the `$position` argument of `add_menu_page`,
 PHP will convert it to an integer which overrides any other menu items
 with that position.

 Per the [http://php.net/manual/en/language.types.array.php PHP docs]...

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

 You can see this happening with the following snippet. The Test 2 menu
 item will show but Test 1 will not.
 {{{#!php
 <?php
 add_action( 'admin_menu', function() {
         add_menu_page( 'Test 1', 'Test 1', 'manage_options', 'test-1', '',
 '', 64 );
         add_menu_page( 'Test 2', 'Test 2', 'manage_options', 'test-2', '',
 '', 64.99 );
 } );
 }}}

 However, if you pass `64.99` in as a string instead of a float, Test 1
 will show.

 Patch attached, thanks!

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40927>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list