WordPress Snippets at WPcustoms

Limit client admin menu access

Restrict access for a specified username and limit their access in the site’s admin panel.


/**
 * Snippet Name: Limit client admin menu access
 * Snippet URL: http://www.wpcustoms.net/snippets/limit-client-admin-menu-access/
 */
 function wpc_remove_client_menus()
{
    global $menu;
    global $current_user;
    get_currentuserinfo();
 
    if($current_user->user_login == 'clients-username')
    {
        $restricted = array(__('Posts'),
                            __('Media'),
                            __('Links'),
                            __('Pages'),
                            __('Comments'),
                            __('Appearance'),
                            __('Plugins'),
                            __('Users'),
                            __('Tools'),
                            __('Settings')
        );
        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', 'wpc_remove_client_menus');