GG资源网

WordPress过滤器:wp_authenticate_user无法获取用户数据

问题描述:

For a WordPress + WooCommerce setup, I\'m trying to implement email activation and Google Captcha function on login using wp_authenticate_user filter, but the order of checking these are wrong.

Ok scenario

  1. Blank username and password without Captcha submit > get the correct error saying the password is blank.

  2. Invalid username without password and Captcha submit > correct error message saying bad username or password.

  3. Valid username with a wrong password with Captcha submit > bad username or password

Bad scenario

  1. valid username with a wrong password without Captcha submit > Captcha error
    (expecting bad username or password).

How can I change this to check Captcha after username and password validation?

Note:

If I switch email activated check to have more priority then I get that error on bad scenario.

Captcha check

Activation check

网友观点:

The function that validates the username/email is hooked to the autenticate filter with the priority 20. And the hooks are added through wp-includes/default-filters.php as you can see below:

So if you want your custom validation functions to run after those default validations, then you should hook to the authenticate filter instead and use 20 (or a higher value - 21, 30, etc.) as the priority:

And change your function declaration so that it looks like so, where the first parameter is either a NULL or WP_User instance on success:

PS: Make certain to check if the $user is a valid user object before accessing its properties and methods. See here for more details. E.g.:

由于网站搬家,部分链接失效,如无法下载,请联系站长!谢谢支持!
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » WordPress过滤器:wp_authenticate_user无法获取用户数据

发表回复

CAPTCHAis initialing...