问题
I'm using the code at https://markwilkinson.me/2014/11/altering-wordpress-admin-menus/ to change plugin-created top-level admin-menu items to submenu items of a 'misc' top-level item.
It works fine on those items which don't have their own submenu, but on items which have their own submenu the submenu disappears.
I don't know if the code can be appropriately modified, or if it can how to do it.
回答1:
Wordpress does not allow you to add a 3rd level of menus in WP admin.
See the answer to How to Add a Third Level Sub Menu to the Wordpress Admin Menu from wordpress.stackexchange.com
The answer from Karthikeyani explains why it currently isn't possible:
The definition of add_submenu_page
requires the parent slug name. For example:
add_menu_page ( 'Test Menu', 'Test Menu', 'read', 'testmainmenu', '', '' );
add_submenu_page ( 'testmainmenu', 'Test Menu', 'Child1', 'read', 'child1', '');
The first parameter of the add_submenu_page
is parent slug name $parent_slug. You may think you could use child1 ($menu_slug) as parent slug name to create the third level, but this does not work.
The parameters definition and source section in the Wordpress developer documentation for add_submenu_page clearly states that you can only use the name of the main menu of the plugin or the file name of the WordPress plugin in parent slug name.
add_submenu_page
Ref: https://developer.wordpress.org/reference/functions/add_submenu_page/
来源:https://stackoverflow.com/questions/45791515/how-can-i-move-admin-menu-top-level-items-to-submenu