如何连接到Wordpress登录系统以编程方式停止某些用户? [英] How do I hook into the Wordpress login system to stop some users programmatically?

查看:76
本文介绍了如何连接到Wordpress登录系统以编程方式停止某些用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基于Wordpress的门户网站,该门户网站与定制的电子商务相集成. 电子商务也充当控制面板":所有角色都在此处设置.一些用户被记录但不活动";他们应该无法登录Wordpress.因此,我需要加入Wordpress登录系统.

I am working on a Wordpress based portal which integrates with a custom-made e-commerce. The e-commerce serves also as a 'control panel': all the roles are set up there. Some users are recorded but 'inactive'; they shouldn't be able to log into Wordpress. For this reason I need to hook into the Wordpress login system.

如果用户是"bad_james",则即使他具有有效的WP登录名和PWD,也无法登录. WP管理面板未提供阻止用户的标记.

If a user is, say, "bad_james", he cannot login, even if he has a valid WP login and PWD. The WP admin panel doesn't provide a a flag to block users.

是否有实现登录过滤器的方法?

Is there a way to implement a login filter?

干杯,
大卫(Davide)

Cheers,
Davide

推荐答案

mjangda回答有一些问题,所以我发布了与WordPress 3.2兼容的版本

There were a few issues with mjangda answer so I'm posting a version that works with WordPress 3.2

主要问题在于return语句.他应该返回一个WP_User对象.另一个问题是优先级不够高.

The main issues were with the return statement. He should be returning a WP_User Object. The other issue was with the priority not being high enough.

add_filter('authenticate', 'check_login', 100, 3);
function check_login($user, $username, $password) {
    // this filter is called on the log in page
    // make sure we have a username before we move forward
    if (!empty($username)) {
        $user_data = $user->data;

        if (/* check to see if user is allowed */) {
          // stop login
          return null;
        }
        else {
            return $user;
        }
    }

    return $user;
}

这篇关于如何连接到Wordpress登录系统以编程方式停止某些用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆