LOGIN_MESSAGE过滤器不工作

时间:2017-11-21 作者:Steve

用户需要通过单击电子邮件发送的链接来验证其电子邮件。链接如下:

http://www.example.com/wp-login.php?token=afdsDEDFdfsSE234&user_id=13
我用过wp_authenticate 钩子以验证用户的令牌:

add_action( \'wp_authenticate\', array($this, \'verify_token\'), 30, 2);
和回调函数:

public function verify_token()
{
        $user_token = afdsDEDFdfsSE234;
        if($user_token == $_GET[\'token\'])
        {
            apply_filters( \'login_message\', __(\'Token mathed. Now login!\',\'user-registration\'));
        }
 }

1 个回复
SO网友:Agustin Prosperi

伙计,你真的需要看看hooks的文件https://codex.wordpress.org/Plugin_API/Action_Reference/wp_authenticatehttps://codex.wordpress.org/Plugin_API/Filter_Reference/login_message

Wp\\u authenticate接收一个参数,也接收login\\u消息,但不是apply\\u filter,而是需要使用add\\u filter来显示如下消息:

add_action( \'wp_authenticate\', array($this, \'verify_token\'), 30, 1);
// even if you aren\'t using the $username you need to declare it in the function
public function verify_token($username){
    $user_token = afdsDEDFdfsSE234;
    if($user_token == $_GET[\'token\']){
        // the filters always return a value and receive at least one
        add_filter( \'login_message\', function($message){
            return __(\'Token mathed. Now login!\',\'user-registration\');
        });
    }
}
在使用你不知道的钩子之前,阅读文档,它们甚至有代码示例。

结束

相关推荐

当返回值为空时,Apply_Filters为什么要返回非空字符串?

因为这个把我的键盘弄坏了。进行了正确的安装,将数据库上载到新的MySQL,并一直在正确使用子主题。但有件事困扰着我,我想不出来。在我的新安装上(ver2.whowhatwhy.com) 我故意将一些小部件留空。我想,当阅读default-widgets.php wp中的文件包括在该小部件上不会显示标题元素。相反,显示标题小部件是因为,出于某种原因,传递的值apply_filters 是一个空格,而不是空白值$instance[\'title\'] 为空。$title = apply_filters( \'