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 am trying to hide a certain amount of menus for a client. Right now I am using the following code and it is doing its job well, but it removes it for everyone as far as I can tell. As in all roles.

function remove_menus () {
global $menu;
    $restricted = array(__('Dashboard'), __('Media'), __('Links'),      __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Profile'),__('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');

What is the line I would use to have this call out only an editor or an author etc?

Thanks much

share|improve this question

3 Answers 3

Use the current_user_can() function to build that $restricted array in pieces, before you pass it through that unset loop. You'll have to use capabilities, and not role names, to make it work.

share|improve this answer

you can do this, it hides the menu (thats all , they can still go to the menu url if they know it), based on capability. You can easily change it to role or even username.

I think user role is "user_role" and for username it is "user_login". The example below uses "user_level" of 10 meaning everyone but the admin.

function remove_menus()
{
    global $menu;
    global $current_user;
    get_currentuserinfo();

    if($current_user->user_level < 10)
    {
        $restricted = array(__('Pages'),
                            __('Media'),
                            __('Links'),
                            __('Custom Post Name'),
                            __('Comments'),
                            __('Appearance'),
                            __('Plugins'),
                            __('Users'),
                            __('Tools'),
                            __('Settings'),
                            __('Posts'),

        );
        end ($menu);
        while (prev($menu)){
            $value = explode(' ',$menu[key($menu)][0]);
            if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
        }// end while

    }// end if
}
add_action('admin_menu', 'remove_menus');
share|improve this answer

If you dont mind using a plugin instead of hard-code try using:

http://wordpress.org/extend/plugins/adminimize/

I use it for all the sites I create to customize what the different roles see, it gives you alot of options and not just on the menus.

share|improve this answer

Your Answer

 
discard

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