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.

I saw this snippet to remove menus:

function remove_menus () {
global $menu;
    $restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
    end ($menu);
    while (prev($menu)){
        $value = explode(' ',$menu[key($menu)][0]);
        if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    }
}
add_action('admin_menu', 'remove_menus');

Is there a way to restrict specific menus, but just for the "editor role"?

I tried something like:

$_the_roles = new WP_Roles();
$_the_roles->remove_cap('editor','moderate_comments');

But I still see the comments menu...

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Here is your answer:

function remove_menus () {
global $menu;

if( (current_user_can('install_themes')) ) { 
$restricted = array(); } // check if admin and hide nothing
else { // for all other users


if ($current_user->user_level < 10)
$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins')); // this removes a lot! Just delete the ones you want to keep showing
end ($menu);
while (prev($menu)){
    $value = explode(' ',$menu[key($menu)][0]);
    if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
}

add_action('admin_menu', 'remove_menus');

You can tailor this to suit whatever role the user has by adjusting the if( (current_user_can('install_themes') argument

See here for more http://codex.wordpress.org/Function_Reference/current_user_can

share|improve this answer
    
Forgot to mention that you can paste this in your theme's functions.php file. Good luck :-) –  Sol Mar 16 '12 at 1:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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