[wp-trac] [WordPress Trac] #52035: The `add_submenu_page()` position is ignored.

WordPress Trac noreply at wordpress.org
Sat Jul 6 00:35:53 UTC 2024


#52035: The `add_submenu_page()` position is ignored.
-------------------------------------+------------------------------
 Reporter:  Howdy_McGee              |       Owner:  (none)
     Type:  defect (bug)             |      Status:  new
 Priority:  normal                   |   Milestone:  Awaiting Review
Component:  Administration           |     Version:
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  administration
-------------------------------------+------------------------------
Changes (by rajinsharwar):

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


Comment:

 So according to https://core.trac.wordpress.org/ticket/39776#comment:18,
 it says **"If a number larger than the number of items is passed, it is
 appended to the end"**. So, if the number passed is greater than the
 number of sub-menus, it will be auto appended in the end.

 I have modified my PR to change this. Now the Menu items will be added in
 the array pretty much with the key of it's position passed. So now the
 array with the menu items would look like:


 {{{
    [0] => Array
         (
             [0] => My Custom Page
             [1] => manage_options
             [2] => my_top_level_slug
             [3] => My Custom Page
         )
     [200] => Array
         (
             [0] => My Custom Page - 1
             [1] => manage_options
             [2] => my_top_level_slug
             [3] => My Custom Page - 1
         )
     [100] => Array
         (
             [0] => My Custom Page - 2
             [1] => manage_options
             [2] => my_top_level_slug
             [3] => My Custom Page - 2
         )
 }}}

 Of course, after the ksort, the arrays are arranged in ascending. this
 solves the issue that whenever any higher value is passed, it still
 follows the same rule of priority. Modified the unit test as well, so I do
 not think any new unit tests are necessary.

 Feel free to add your thoughts!

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


More information about the wp-trac mailing list