Wordpress 身份验证过滤器 [英] Wordpress Authenticate Filter

查看:25
本文介绍了Wordpress 身份验证过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试覆盖 Wordpress 的 wp_authenticate 函数(不修改核心文件,主要是 pluggable.php),但是我不确定我是否以正确的方式进行.有两个很好的参考文献(见下文),但它们没有明确说明在满足某些条件的情况下如何防止登录.

I'm currently trying to override Wordpress' wp_authenticate function (without modifying the core files, mainly pluggable.php), however I'm not sure if I'm going about it the correct way. There are two great references (see below), but they don't explicitly state what to do in order to prevent the login provided certain criteria are met.

简而言之,我试图阻止尚未激活其帐户的注册用户.我已经实现了在 usermeta 表(附加到他们的用户 ID)中创建一个具有 md5 唯一 ID 的用户.我基本上是在登录时检查 usermeta 表中的activation_key"值,如果存在值,我想防止登录发生.

In short, I'm trying to prevent registered users who have not activated their account. I've already implemented creating a user with a md5 unique id in the usermeta table (attached to their user id). I'm basically trying to check for that "activation_key' value in the usermeta table on login, if a value exists, I want to prevent the login from occurring.

身份验证过滤器似乎正是我需要的,但是在修改它并将其放入我的functions.php 文件后,它似乎不起作用!正常登录.

The authenticate filter seems to be exactly what I need but after modifying it and placing it into my functions.php file, it doesn't seem to work! Login occurs per usual.

参考文献:

如何我应该挂入 Wordpress 登录系统以编程方式阻止某些用户吗?

http://willnorris.com/2009/03/authentication-in-wordpress-28

推荐答案

我实际上找到了解决方法.

I actually found a work around.

使用自定义表单,您可以使用 wp_signon 函数登录 Wordpress.

Using a custom form you can log into Wordpress using the wp_signon function.

var $creds = array();
$creds['user_login'] = 'example';
$creds['user_password'] = 'plaintextpw';
$creds['remember'] = true;
//check if user has an activation key in the usermeta table
$user = get_userdatabylogin($creds['user_login']); 
if(get_usermeta($user->ID,'activation_key')) { 
} else {
$procLogin = wp_signon( $creds, false );
if ( is_wp_error($procLogin) ) {
echo $user->get_error_message();
} 
echo 'success!';
}

希望这能帮助到那里的人

hope this helps someone out there

这篇关于Wordpress 身份验证过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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