[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
Tue Mar 29 04:33:46 UTC 2022


#40927: Passing a float as the position in add_menu_page can override other menu
items
-------------------------------------------------+-------------------------
 Reporter:  justinbusa                           |       Owner:
                                                 |  SergeyBiryukov
     Type:  defect (bug)                         |      Status:  reviewing
 Priority:  normal                               |   Milestone:  6.0
Component:  Administration                       |     Version:  4.8
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch dev-feedback needs-        |     Focuses:
  testing needs-refresh needs-unit-tests         |  administration
-------------------------------------------------+-------------------------
Changes (by peterwilsoncc):

 * keywords:  has-patch dev-feedback needs-testing => has-patch dev-feedback
     needs-testing needs-refresh needs-unit-tests


Comment:

 I've linked a [https://github.com/WordPress/wordpress-develop/pull/2471
 pull request] based on [attachment:"40927.2.patch"] to get the tests
 running.

 The tests are currently failing, I suspect due to the following:

 * PR is storing with the array key `(string) $position + (a tiny randomish
 number)` whereas the tests are testing for the key `(int) $position`.
 * change in sorting algorithm, possibly.

 ----

 For now, let's target the bug that passing different values can result in
 an override (64.64 replacing 64).

 Avoiding collisions with a tiny randomish number can wait as it's
 documented that only one menu item can own a `$position` value.

 It's strongly advised against but it is currently possible to manipulate
 the `$menu` global directly. For example, I could remove the comments menu
 with:

 {{{#!php
 <?php
 global $menu;
 unset( $menu[25] );
 }}}

 It's not a good idea to do so but it would be nice not to break backward
 compatibility if other options are available.

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


More information about the wp-trac mailing list