0

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...

2

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

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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