[wp-trac] [WordPress Trac] #15595: add_menu_page position conflict

WordPress Trac wp-trac at lists.automattic.com
Fri Apr 8 17:20:30 UTC 2011


#15595: add_menu_page position conflict
--------------------------+-----------------------------
 Reporter:  vegasgeek     |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  Future Release
Component:  Plugins       |     Version:  3.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |
--------------------------+-----------------------------

Comment (by aaroncampbell):

 I just thought I'd drop my thoughts here as I'm fighting this yet again.
 I know that currently the $position parameter is treated as an absolute
 demand, but in reality I think the most intuitive way for this to work
 would be to check for a conflict and if one exists to shift everything up
 to make room for the new item.

 I just wanted to add a menu item near the top, but position 3 was taken,
 position 4 was the separator I wanted to be above, and position 5 was
 taken as well.  I ended up having to write some really ugly code to do
 what I wanted that grabbed the menu global, took the keys from it, reverse
 sorted them and filtered out anything < 4, ran through them all doing
 `$menu[$key+1] = $menu[$key]; unset($menu[$key])`, had to `ksort($menu)`,
 and then inserted my menu item into position 4.  It would have been a lot
 easier if I could have used array_splice, but that resets the keys.

 Maybe we could have add_menu_page() do something similar and then
 increment all the $_wp_last_*_menu vars that are >= the position we
 inserted into?

 It's all rather messy honestly.  I wish that there weren't all these empty
 spaces so we could simply array_splice in a new menu item and track the
 various sections using the $_wp_last_*_menu vars.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15595#comment:10>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list