How to hide Admin Tabs? [duplicate]

You could use this code (below is just an example for 3 random tabs)

function disable_user_profile() {
    if ( !current_user_can( 'publish_posts' ) ) { 
        wp_redirect( admin_url('index.php') ); 
    }
}
add_action( 'load-profile.php', 'disable_user_profile' ); // disable profile tab
add_action( 'load-tools.php', 'disable_user_profile' ); // disable tools tab
add_action( 'load-edit.php', 'disable_user_profile' ); // disable posts tab

The if ( !current_user_can( 'publish_posts' ) ) = user capability
The wp_redirect( admin_url('index.php') ); = I put here so they stay in backend, even if they try to add the link to that page in url
The add_action( 'load-profile.php', = tab which should not be accessible.(in this case the profile tab)

If I am correct then the sample here disables the tabs for Contributor and Subscriber.


Edit
Assuming you won’t use this only for your theme but for the whole backend (So it is active also when switching theme’s) a sample plugin with the code is to find below.
Create a file ie. disable_tabs.php , and use the code below (it is incl. the above sample).

<?php
*Plugin Name: Hide Tabs in Admin panel
*Description: Hiding tabs for certain user levels.
*Author Name: Who ever you want
*
    function disable_user_profile() {
    if ( !current_user_can( 'edit_posts' ) ) { 
        wp_redirect( admin_url('index.php') ); 
    }
}
add_action( 'load-profile.php', 'disable_user_profile' ); // disable profile tab
add_action( 'load-tools.php', 'disable_user_profile' ); // disable tools tab
add_action( 'load-edit.php', 'disable_user_profile' ); // disable posts tab
?>