2

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

4

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');
2

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.

1

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.

Your Answer

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