WordPress根据用户名来限制管理菜单项目的访问

2012-05-06 20:41:46来源:stackexchange作者:

 

 

如果你希望你的管理菜单的某些项对某些用户可见,那么这个代码就会帮到你。只需替换 functions.php 中的 clients-username 为如下代码即可:

function remove_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', 'remove_menus');

关键词:WordPress

赞助商链接: