简体   繁体   English

如何为非管理员用户隐藏仪表板菜单项

[英]How can I hide a dashboard menu item for non-admin users

I have a custom plugin made, but I want this only to be visible for admins.我制作了一个自定义插件,但我希望它只对管理员可见。 I figured this one out:我想出了这个:

function remove_by_caps_admin_menu() {功能 remove_by_caps_admin_menu() {

if (is_admin() ) {
    }else{
remove_menu_page( 'edit.php?post_type=registered_email' );}}

add_action('admin_menu', 'remove_by_caps_admin_menu', 999); add_action('admin_menu', 'remove_by_caps_admin_menu', 999);

this hides the menu-item for admin users.这隐藏了管理员用户的菜单项。 but want to display it to admin users ONLY.但只想将其显示给管理员用户。

    
    if (!is_admin() ) {
        }else{
    remove_menu_page( 'edit.php?post_type=registered_email' );
}
}
add_action('admin_menu', 'remove_by_caps_admin_menu', 999);```

this doesn't work when I login as an author.

This will fix -这将解决 -

add_action('admin_menu', 'remove_by_caps_admin_menu');

function remove_by_caps_admin_menu(){
    if( !current_user_can( 'administrator' ) ){
        remove_menu_page( 'edit.php?post_type=registered_email' );
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何隐藏 Wordpress 仪表板中的管理菜单项? - How do I hide the Admin Menu item in Wordpress Dashboard? 如何使用 JWT 和 flutter_wordpress 包在 Flutter 应用程序中对 WordPress 非管理员用户进行身份验证? - How do I authenticate WordPress non-admin users in a flutter app with JWT and flutter_wordpress package? 如何减少非管理员用户上传的文件大小? - How to decrease file size upload for non-admin users? 在Wordpress的“管理菜单”中,如何隐藏菜单项,但仍然允许所有人访问它? - In the Wordpress Admin Menu, how can I hide a menu item but still allow everyone to have access to it? WordPress-做到这一点,以使非管理员用户无法看到具有特定自定义帖子状态的帖子 - Wordpress - Make it so that non-admin users can't see posts with a specific custom post status 如何从非管理员菜单中隐藏“WooCommerce”? - How to hide “WooCommerce” from menu for non admin? 如何从管理仪表板中删除/隐藏 wordpress 菜单 - how to remove/hide wordpress menu from admin dashboard 如何从管理仪表板中删除/隐藏 wordpress 插件菜单 - how to remove/hide wordpress plugin menu from admin dashboard 如何确保Wordpress管理仪表板菜单项是第一个 - How to ensure Wordpress admin dashboard menu item is first 如何将Javascript添加到Wordpress中的每个非管理页面? - How do I add Javascript to every non-admin page in Wordpress?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM