简体   繁体   中英

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() {

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

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' );
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM