I'm trying to hide tabs of admin panel like Posts, Pages, etc...
I tried Admin Menu Editor without success.
I'm trying to hide tabs of admin panel like Posts, Pages, etc...
I tried Admin Menu Editor without success.
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.
<?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
?>