Possible to hide Custom Post Type UI/Menu from specific User Roles?

To hide a post type menu item from non-admin users:

function wpse28782_remove_menu_items() {
    if( !current_user_can( 'administrator' ) ):
        remove_menu_page( 'edit.php?post_type=your_post_type' );
    endif;
}
add_action( 'admin_menu', 'wpse28782_remove_menu_items' );

your_post_type should be the name of your actual post type.

EDIT-

other menu pages you can remove:

remove_menu_page('edit.php'); // Posts
remove_menu_page('upload.php'); // Media
remove_menu_page('link-manager.php'); // Links
remove_menu_page('edit-comments.php'); // Comments
remove_menu_page('edit.php?post_type=page'); // Pages
remove_menu_page('plugins.php'); // Plugins
remove_menu_page('themes.php'); // Appearance
remove_menu_page('users.php'); // Users
remove_menu_page('tools.php'); // Tools
remove_menu_page('options-general.php'); // Settings

EDIT 2 –

Removing plugin menu items.

For plugins, it seems you only need the page= query var. The other thing to note is the priority, which is the third argument to the admin_menu add_action. It has to be set low enough (the higher the number, the lower the priority) so that plugins have already added themselves to the menu.

function wpse28782_remove_plugin_admin_menu() {
    if( !current_user_can( 'administrator' ) ):
        remove_menu_page('cart66_admin');
    endif;
}
add_action( 'admin_menu', 'wpse28782_remove_plugin_admin_menu', 9999 );

Leave a Comment