[wp-hackers] Change in plugin Options page handling

Sebastian Herp newsletter at scytheman.net
Tue Feb 22 21:46:54 GMT 2005


Owen Winkler wrote:

> Ryan Boren wrote:
>
>> We need to add the hook support to add_menu_page() and make sure
>> add_menu_page() followed by an add_submenu_page() build a proper
>> hierarchy.  Want to take a crack at it?  I can't look at it right now.
>
>
> Well, after a couple hours of tinkering, this just ain't gonna happen 
> with the current code.

Interesting, I am thinking exactly the same after the last 2 hours of 
trying :-(

>
> The primary reason is that the submenus use this format for their URL:
>
> /wp-admin/parent_page.php?page=plugin_page.php
>
> If a plugin supplies more than one tab for a single main menu, there 
> is no way to determine which one to display.  This is very likely in 
> the case that a plugin supplies its own top-level menu.
>
> Similarly, adding a new top-level menu page with add_menu_page() in 
> the style of add_submenu_page() - where the content of the page is 
> output from a plugin hook sink function - would require some stub file 
> to display the menu.  Why?  You can't pass the plugin filename as both 
> the parnet_page and the plugin_page in the URL above because that 
> would redeclare all of the plugin functions.  (I'm trying to avoid 
> is_plugin_page() as per the mosquito discussion on this topic.)
>
> Maybe there's a simple solution that I'm not seeing, and I'm sorry if 
> I'm blind to it, but it seems to me that the menu system is going to 
> need a greater overhaul than a few tweaks.

I fixed the very strange menu-behaviour with having my plugin produce 
its own submenu. The problem is that the top level menu wont get 
highlighted if you add no submenu to it, but that is a minor problem. I 
really need more than one submenu under a custom top-level menu and this 
does it for me (for now) ... has the advantage that it works on 1.5 and 
needs no patch.

Example:
<?php
if(is_plugin_page()) {
?>
    <ul id="adminmenu2">
      <li><a href="admin.php?page=<?php echo basename(__FILE__) 
?>&mode=main" <?php if($_GET['mode'] == '' || $_GET['mode'] == 'main') 
echo "class=\"current\"";?>><?php echo __('Mainpage') ?></a></li>
      <li><a href="admin.php?page=<?php echo basename(__FILE__) 
?>&mode=mode1" <?php if($_GET['mode'] == 'mode1') echo 
"class=\"current\"";?>><?php echo __('Mode1') ?></a></li>
      <li><a href="admin.php?page=<?php echo basename(__FILE__) 
?>&mode=mode2" <?php if($_GET['mode'] == 'mode2') echo 
"class=\"current\"";?>><?php echo __('Mode2') ?></a></li>
      <li><a href="admin.php?page=<?php echo basename(__FILE__) 
?>&mode=mode3" <?php if($_GET['mode'] == 'mode3') echo 
"class=\"current\"";?>><?php echo __('Mode3') ?></a></li>
    </ul>    
   
    <div class="wrap">
    blablabla plugin page
    </div>
<?php

if (! function_exists('example_admin_menu')) {
function example_admin_menu() {
    add_menu_page('Testing Titel', 'Testing', 5, __FILE__);
}

add_action('admin_menu', 'example_admin_menu');
?>

>
> I'm still thinking about it, though...

Same here ... there must be a dirty dirty hack for this or all future 
plugin-users upgrade to a version where this is fixed *hoping*


Sebastian


More information about the hackers mailing list