add_submenu_page not working

时间:2014-06-15 作者:danyo

我构建了一个插件,可以创建如下自定义菜单:

    add_menu_page( \'Wholesale Pricing\', \'Wholesale\', \'manage_options\', \'woo-wholesale\', \'woo_wholesale_page_call\'); 
我现在正试图在下面添加一个子页面项。我读了抄本,想出了:

add_submenu_page( \'woo-wholesale\', \'Registrations\', \'Registrations\', \'manage_options\', \'woo-wholesale-registrations\', \'wwpr_page_call\' ); 
我猜这是不正确的,因为子菜单项没有显示。有人能解释一下吗?

2 个回复
SO网友:Abhineet Verma

确保您的add_action 挂钩设置为“管理”菜单。

以下是示例代码:

add_action(\'admin_menu\', \'wpse149688\');
function wpse149688(){
    add_menu_page( \'Wholesale Pricing\', \'Wholesale\', \'manage_options\', \'woo-wholesale\', \'woo_wholesale_page_call\');
    add_submenu_page( \'woo-wholesale\', \'Registrations\', \'Registrations\', \'manage_options\', \'woo-wholesale-registrations\', \'wwpr_page_call\' ); 
}
还要检查您登录的用户是否能够查看此菜单。由于此菜单是使用manage_options 功能

SO网友:ban-geoengineering

我犯了与OP相同的错误,因为如何让它工作起来并不直观。通过阅读Administration Menus, 我找到了答案。

问题(对我来说)是编辑$parent_slug 调用中的参数add_submenu_page(...).

因此,在OP的情况下,您可以更改:

add_submenu_page( 
    \'woo-wholesale\', 
    \'Registrations\', 
    \'Registrations\', 
    \'manage_options\', 
    \'woo-wholesale-registrations\', 
    \'wwpr_page_call\' 
);
收件人:

add_submenu_page( 
    \'edit.php?post_type=woo-wholesale\', 
    \'Registrations\', 
    \'Registrations\', 
    \'manage_options\', 
    \'woo-wholesale-registrations\', 
    \'wwpr_page_call\' 
);

结束

相关推荐