[wp-hackers] Two admin submenus?

Ryan Boren ryan at boren.nu
Tue Nov 30 23:48:02 UTC 2004


On Tue, 2004-11-30 at 16:17 -0500, Owen Winkler wrote:
> Has anyone come up with a way to add submenu options into more than one 
> main admin menu?
> 
> I would like to insert a submenu into Manage and into Options with 
> different access levels but from a single plugin file.  Is there a way 
> to do this?

Having the same file in two different submenus confuses
get_admin_page_parent().  If you visit admin.php?page=myplugin.php, the
parent will always be Manage since Manage comes before Options in the
menu array.  Perhaps we could add an optional query string argument to
the add_*_page functions.

add_options_page(__("Foo Options"), __('Foo'), 5, __FILE__ ,
'mode=options');

add_management_page(__("Manage Foo"), __('Foo'), 5, __FILE__,
'mode=manage');

The query string, if present, would be used along with the filename to
create a unique key when building the submenus.   When the plugin page
is loaded, get_admin_page_parent() would have to check $_GET['mode'] to
determine the parent.  This means all links to the page would have to
have mode= so that the correct parent is picked.  Kinda ugly.

With the parent determined, the query would be passed along to admin.php
so that the plugin could check $_GET['mode'] to see if it should display
the Options or Manage page.

I don't know.  Maybe we should just use multiple files.  Stick them in a
subdirectory of plugins/ and save some grief. ;-)

Ryan





More information about the hackers mailing list