Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This question is an exact duplicate of:

I'm trying to hide tabs of admin panel like Posts, Pages, etc...

I tried Admin Menu Editor without success.

share|improve this question

marked as duplicate by brasofilo, toscho Dec 3 '13 at 4:04

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Recommendation questions are off-topic in most of Stack Exchange. I've removed this part from your post to acomodate it. Anyway, you should research here, there are plenty of solutions. –  brasofilo Nov 28 '13 at 6:27

1 Answer 1

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
?>
share|improve this answer
    
Take a look at Where to put my code: plugin or functions.php? –  brasofilo Nov 28 '13 at 6:20
    
Made some changes, Brasofilo is right about not using it in just one theme but "system wide". (Personally I would place it in mu-plugins, but thats just me) –  Charles Nov 28 '13 at 12:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.