[英]Cannot access custom admin menu page WordPress
I've been trying to register custom admin menu using the following code我一直在尝试使用以下代码注册自定义管理菜单
function bbtre_register_admin_page(){
add_menu_page('Revenue Share Settings', 'Reshare', 'manage_options', 'reshare-settings', 'bbtre_admin_page_callback');
}
add_action('admin_init', 'bbtre_register_admin_page');
function bbtre_admin_page_callback(){
echo "<h1>Hell</h1>";
}
The code is working well as I can see my custom admin menu appears on the dashboard, but when click on the menu, I found that I have no permission to access the page.代码运行良好,因为我可以看到我的自定义管理菜单出现在仪表板上,但是当单击菜单时,我发现我没有访问该页面的权限。
Here is the message: Sorry, you are not allowed to access this page.这是消息:抱歉,您无权访问此页面。
I've been trying to find the solution on WordPress codes, but it deosn't help even I change the capability 'switch_themes'.我一直在尝试找到有关 WordPress 代码的解决方案,但即使我更改了“switch_themes”功能,它也无济于事。
Anyone please kindly help me to solve the problem?任何人请帮助我解决问题?
Note: I'm working on Wordpress 9.4 and Xampp注意:我正在研究 Wordpress 9.4 和 Xampp
Change the hook to add_action('admin_menu', 'bbtre_register_admin_page');
将钩子更改为
add_action('admin_menu', 'bbtre_register_admin_page');
to add menu on admin dashboard在管理仪表板上添加菜单
Here is the completed code as add_action
can be on above function.这是完成的代码,因为
add_action
可以在上面的函数上。
add_action( 'admin_menu', 'register_my_custom_menu_page' );
function register_my_custom_menu_page() {
//add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); // for ideal practice
add_menu_page('Revenue Share Settings', 'Reshare', 'manage_options', 'reshare-settings', 'bbtre_admin_page_callback','',''); // for your code
}
function bbtre_admin_page_callback(){
echo "Hello";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.