I am working on creating an administration menu within WordPress for a plugin. I have successfully registered the menu using add_menu_page() and it shows in the sidebar as expected. I have also added a couple of sections within the menu using add_submenu_page().
It appears that WordPress (running 3.05) is not correctly indicating which menu item should be activated as “current”.
When I add a test page to the main Dashboard menu this is what I see:
http://dl.dropbox.com/u/3019972/wp-screen1.png
As you can see the current page is visually correct within the menu and is given a class of “current”. However on my own menu it looks like this:
http://dl.dropbox.com/u/3019972/wp-screen2.png
In this example I would expect “Dashboard” to be highlighted.
Is this simply a WordPress bug? or do I need to provide special code to make this work within my own menu?
Updated with code examples
The code I am using for adding and creating menus looks like this:
add_action('admin_menu','my_admin_menu');
function my_admin_menu() {
// this test works as expected
// add_submenu_page( 'index.php', 'test', 'test', 'read', 'admin.php?page=plugin-dashboard','my_pluggin_dashboard' );
// my main menu menu
add_menu_page(__('My Plugin', 'myplugin'),__('My Plugin', 'myplugin'), 'edit_posts','admin.php?page=plugin-dashboard','my_plugin_dashboard','icon');
// dashboard submenu - this fails to highlight with current
add_submenu_page('admin.php?page=plugin-dashboard', __('Dashboard','myplugin'), __('Dashboard','myplugin'), 'edit_posts', 'admin.php?page=plugin-dashboard', 'my_plugin_dashboard' );
// settings submenu - this fails to highlight with current
add_submenu_page('admin.php?page=plugin-dashboard', __('Settings','myplugin'), __('Settings','myplugin'), 'manage_options', 'admin.php?page=my-plugin-settings', 'my_plugin_settings' );
}
I have commented the code that works and the code that does not behave as I expect. Thanks for your comments.
Try this:
Essentially: don’t use full page links with admin.php?… as the page slug. Especially if you are passing callbacks, just use a slug, not a page address.