是否有任何操作/筛选器挂钩可用于禁用某些用户角色的登录?

时间:2018-10-08 作者:I am the Most Stupid Person

我想阻止名为“挂起”的用户角色登录到该站点。(pending是我创建的自定义用户)。

是否有任何操作/筛选器阻止所有处于“pendin”用户角色的用户?

1 个回复
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成

是的,有。您可以使用authenticate 挂钩:

add_action( \'authenticate\' , \'check_custom_authentication\', 20, 3 );
        
         
function check_custom_authentication ( $user, $username, $password ) {
            
    if ( is_a($user, \'WP_User\') && in_array(\'pending\', $user->roles) ) {
        return new WP_Error(\'pending\', \'Your error msg\');
    }
}

结束

相关推荐

Change default login auth

我将增强我的WordPress身份验证页面。我的想法很简单,就是更改过程以检查密码,就像使用用户名或电子邮件登录的默认过程一样。我已经更改了数据库,添加了额外的字段“code”:我的目标是:the user can login with your username or email and with your password or code.然而,我不知道哪个部分的编码是用来验证密码的,因为我想参考现有的编码。