Reputation: 21
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.
Upvotes: 0
Views: 1528
Reputation: 166
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' );
}
}
Upvotes: 0