[wp-hackers] Strange behavior in plugin with main menu and submenu

Jennifer Hodgdon yahgrp at poplarware.com
Sun Jul 1 14:41:39 GMT 2007


Yes, I think the Codex doc is correct. But there are two differences 
between what you did and what I have seen work in a plugin:

a) In a previous plugin, I put a function name in for the top-level 
menu (supposedly optional last argument to add_menu_page). That may 
not be necessary.

b) You have set the file argument in add_submenu_page to ''. It needs 
to be set to the plugin file.

With these two changes, your calls would be:

function test_menu() {
    add_submenu_page(__FILE__,'A','A',1,'__FILE__','page_a');
    add_submenu_page(__FILE__,'B','B',1,'__FILE__','page_b');
    add_menu_page('Test','Test',1,__FILE__, 'page_a');
}

Try that and see if it works...
      Jennifer

Leonid Mamchenkov wrote:
> I am writing a self-contained plugin, which adds an item to
> administration's main menu. It also adds a few submenus to its main
> menu item.  I want all code and formatting and everything to remain in
> the same file.  It seems possible judging by this Codex page:
> http://codex.wordpress.org/Adding_Administration_Menus , but I can't
> make it work.

> 
> <?php
> /**
> * Plugin Name: Test
> * Version: 1.0
> */
> 
> function test_menu() {
>    add_submenu_page(__FILE__,'A','A',1,'','page_a');
>    add_submenu_page(__FILE__,'B','B',1,'','page_b');
>    add_menu_page('Test','Test',1,__FILE__);
> }

[... rest snipped... ]

-- 
Jennifer Hodgdon

Poplar ProductivityWare * www.poplarware.com
Web Databases/Scripts * Modeling/Analysis/Palm OS Software


More information about the wp-hackers mailing list