[wp-hackers] Change in plugin Options page handling

Michael D.Adams mikea at turbonet.com
Sat Feb 19 13:43:24 GMT 2005


[NOTE:  I accidentally sent this message from the wrong email address 
initially.  It got moderated, so I'm sending it from the right address. 
  Sorry if you end up with two copies.
MODERATOR: Can you NOT approve this message's duplicate? :) ]

In attempting to update Codex ( 
http://codex.wordpress.org/Plugin_API#Adding_submenus_to_the_admin_menu 
) regarding the new submenu handling, I've run into a few questions I'm 
hoping someone can answer for me.

First, my test plugin.  Call it example.php

<?php
/*
Plugin Name: Example
Description: Example plugin that adds submenus all over the place.
Author: WordPress
Version: 1.0
*/
function example_page() {
?>
         <div class="wrap">
         <h2>Example</h2>
         <p>This example plugin adds submenus all over the place.</p>
         <p>It also adds a New Menu to the menu bar, but is unable
		to add a submenu to that New Menu.</p>
         </div>
<?php
}

function example_admin_menu() {
	// adds new menu called New - example2.php is another file - suppose 
it only contains:
	// <div class="wrap">NEW menu!</div>
	add_menu_page('New Menu', 'New', 5, 'example2.php');

	 // 404 - wp-admin/example2.php?page=example.php
	add_submenu_page('example2.php', 'ExNew', 'ExNew', 5, __FILE__, 
'example_page');

	// adds example to the Write menu (as a submenu)
	add_submenu_page('post.php', 'Example', 'Example', 5, __FILE__, 
'example_page');

	// adds example to the Options menu (as a submenu)
	add_options_page('Example', 'Example', 5, __FILE__, 'example_page');

	// adds example to the Manage menu (as a submenu)
	add_management_page('Example', 'Example', 5, __FILE__, 'example_page');
}

// runs the function to add those menus
add_action('admin_menu', 'example_admin_menu');
?>


First, unlike add_submenu_page, add_menu_page must reference a complete 
file - not a function within a file, forcing the plugin author to 
either include a new file ('example2.php' in the above) or test for 
is_plugin_page.  Is there a reason add_menu_page was not altered to 
match add_submenu_page?

Second, the above plugin fails to add a submenu to the new, author 
defined menu (called "New" above).  When the submenu tab is clicked, an 
attempt to access the URI 'wp-admin/example2.php?page=example.php' is 
made.  Clearly, this won't work.  So, what's the right way to add a 
submenu to a new, author defined menu?

Thanks,
Michael Adams
mdawaffe




More information about the hackers mailing list