[wp-hackers] Change in plugin Options page handling

Joshua alphaoide at yahoo.com
Mon Feb 21 06:49:48 GMT 2005


> So, what's the right way to add a submenu to a new,
author defined menu?
I'd like to know, too.


-----Original Message-----
From: hackers-bounces at wordpress.org
[mailto:hackers-bounces at wordpress.org]
On Behalf Of Michael D.Adams
Sent: Saturday, February 19, 2005 5:43 AM
To: hackers at wordpress.org
Subject: Re: [wp-hackers] Change in plugin Options
page handling

[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


_______________________________________________
hackers mailing list
hackers at wordpress.org
http://wordpress.org/mailman/listinfo/hackers




		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250


More information about the hackers mailing list