plugin development - How do I add a custom sublevel menu specified in one directory to a custom top level menu specified in anot

I'm working on a plugin that constructs a top level menu and resides within its own directory in wp-contentplugin

I'm working on a plugin that constructs a top level menu and resides within its own directory in /wp-content/plugins.

For example, the plugin looks like this:

function main_menu() {
  if(function_exists('add_menu_page')) {
   add_menu_page('Main Menu Title', 'Main Menu', 'administrator', 'main-menu-handle', 'menu-display');
  } 
}
add_action('admin_menu', 'main_menu');

I would like to build out additional menu items as plugins in the future so that they may reside in their own directory within /wp-content/plugins but will add themselves to this particular custom menu.

Ideally, these new plugins would register themselves like this:

function register_submenu() {
  if(function_exists('add_submenu_page')) {
    add_submenu_page('main-menu-handle', 'Widget Title', 'Widget', 'administrator', 'widget-handle', 'widget_display');
  }
}
add_action('admin_menu', 'register_submenu');

But I can't seem to make this work mainly because of the way WordPress uses the admin.php and the page query string parameter to navigate custom menus.

Any insight?

I'm working on a plugin that constructs a top level menu and resides within its own directory in /wp-content/plugins.

For example, the plugin looks like this:

function main_menu() {
  if(function_exists('add_menu_page')) {
   add_menu_page('Main Menu Title', 'Main Menu', 'administrator', 'main-menu-handle', 'menu-display');
  } 
}
add_action('admin_menu', 'main_menu');

I would like to build out additional menu items as plugins in the future so that they may reside in their own directory within /wp-content/plugins but will add themselves to this particular custom menu.

Ideally, these new plugins would register themselves like this:

function register_submenu() {
  if(function_exists('add_submenu_page')) {
    add_submenu_page('main-menu-handle', 'Widget Title', 'Widget', 'administrator', 'widget-handle', 'widget_display');
  }
}
add_action('admin_menu', 'register_submenu');

But I can't seem to make this work mainly because of the way WordPress uses the admin.php and the page query string parameter to navigate custom menus.

Any insight?

Share Improve this question asked Jan 4, 2011 at 14:31 TomTom 1,0619 silver badges17 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 5

It sounds as if you're having problems adding submenus from a plugin to a parent item registered in another plugin.

Add priorities to your admin_menu actions to make sure the parent(top level) item exists at the point your additional plugins attempt to add items to that menu..

Add top level

add_action('admin_menu', 'main_menu', 100 );

Add sub items

add_action('admin_menu', 'register_submenu', 105 );

Default priority is 10, so your two callbacks were possibly executing in the wrong order.

Let me know if that helps.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745463256a4628803.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信