我可以暂时更改用户在Wordpress中的角色吗?

时间:2014-02-19 18:04:16

标签: wordpress

我需要在Wordpress中为用户授予特定的角色(编辑,管理员等)及其所有功能,但我不想更新他们在数据库中的角色(以便下次他们回来,他们将有他们原来的角色)。我怎么能这样做呢?

1 个答案:

答案 0 :(得分:2)

这是我最终做的事情:

add_filter( 'user_has_cap', 'override_caps' );

function override_caps($allcaps){

    if( ... ){ // When to override caps

        $role_name = 'administrator';
        $role = get_role($role_name); // Get the role object by role name
        $allcaps = $role->capabilities;  // Get the capabilities for the role
        $allcaps[$role_name] = true;     // Add role name to capabilities

    }

    return $allcaps;

}
相关问题