admin管理员组文章数量:1122832
Sorry if this has been asked before; I have been looking for a while, but couldn't find anything directly applicable. I am building my first plugin and I am trying to follow the WP best practices.
My current plugin structure looks like this:
- my-plugin
-- index.php
-- admin (folder
--- sub-menu-page.php
I am trying to keep all of my plugin pages separate as part of my organization. However, I can't seem to point my plugin's submenu link to the sub-menu-page.php
file. Here's my menu code:
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('WISE Admin', 'WISE Admin', 'manage_options', 'wise-menu', 'my_menu_output', 'dashicons-tickets', 2 );
add_submenu_page('wise-menu', 'General Settings', 'General', 'manage_options', 'general-settings', 'general_settings' );
add_submenu_page('wise-menu', 'Submenu Page', 'Submenu Page', 'manage_options', 'admin/sub-menu-page' );
remove_submenu_page('wise-menu', 'wise-menu');
}
The submenu link takes me to /wp-admin/admin/sub-menu-page
which is obviously not where I want to go.
Can I please have some advice for what I am doing wrong?
Sorry if this has been asked before; I have been looking for a while, but couldn't find anything directly applicable. I am building my first plugin and I am trying to follow the WP best practices.
My current plugin structure looks like this:
- my-plugin
-- index.php
-- admin (folder
--- sub-menu-page.php
I am trying to keep all of my plugin pages separate as part of my organization. However, I can't seem to point my plugin's submenu link to the sub-menu-page.php
file. Here's my menu code:
add_action('admin_menu', 'my_menu_pages');
function my_menu_pages(){
add_menu_page('WISE Admin', 'WISE Admin', 'manage_options', 'wise-menu', 'my_menu_output', 'dashicons-tickets', 2 );
add_submenu_page('wise-menu', 'General Settings', 'General', 'manage_options', 'general-settings', 'general_settings' );
add_submenu_page('wise-menu', 'Submenu Page', 'Submenu Page', 'manage_options', 'admin/sub-menu-page' );
remove_submenu_page('wise-menu', 'wise-menu');
}
The submenu link takes me to /wp-admin/admin/sub-menu-page
which is obviously not where I want to go.
Can I please have some advice for what I am doing wrong?
Share Improve this question edited Apr 3, 2019 at 8:41 MikeNGarrett 2,6611 gold badge20 silver badges29 bronze badges asked Mar 5, 2019 at 16:44 user1192309user1192309 112 bronze badges1 Answer
Reset to default 0You're very close.
When you add your first submenu page you want to duplicate your initial menu page. In your second add_submenu_page
you are missing the function callback for that page. Technically this parameter is optional, but it changes your url from /wp-admin/sub-menu-page
to /wp-admin/admin.php?page=sub-menu-page
.
Give this a shot:
add_action( 'admin_menu', 'my_menu_pages' );
function my_menu_pages() {
add_menu_page( 'WISE Admin', 'WISE Admin', 'manage_options', 'wise-menu', 'my_menu_output', 'dashicons-tickets', 2 );
add_submenu_page( 'wise-menu', 'General Settings', 'General', 'manage_options', 'wise-menu', 'my_menu_output' );
add_submenu_page( 'wise-menu', 'Submenu Page', 'Submenu Page', 'manage_options', 'sub-menu-page', 'submenu_settings' );
}
本文标签: Plugin submenu pages recommended structure and links
版权声明:本文标题:Plugin sub-menu pages recommended structure and links 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736287789a1927957.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论