首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用wp_new_user_notification_email筛选器时获取密码密钥

使用wp_new_user_notification_email筛选器时获取密码密钥
EN

WordPress Development用户
提问于 2018-10-12 09:46:45
回答 1查看 1.1K关注 0票数 1

我试图定制发送给新注册用户的电子邮件。我在插件中使用了wp_new_user_notification_email过滤器,它可以很好地设置主题和消息。然而,I希望发送链接来重置用户的密码,就像普通WP通知电子邮件所做的一样。

根据我在wp_new_user_notification函数中所看到的,在存储在数据库中之前,哈希中的密码密钥。然后在url中使用此键重置密码。问题是,我不能在我用wp_new_user_notification_email过滤器调用的函数中访问这个变量,如果我生成一个放进url的randow键,就会在表单中抛出一个错误(可能是因为新键不对应于存储的散列键)。

我想有一种方法可以实现这一点,因为有一个过滤器来自定义注册消息,而不给予重新设置密码的链接将是非常没有意义的。

知道吗?

EN

回答 1

WordPress Development用户

发布于 2018-10-12 09:59:41

我找到了一个函数来检索这个键: get_password_reset_key()。

现在,我的插件中有了以下代码,用于自定义发送给新注册用户的电子邮件:

代码语言:javascript
运行
复制
    add_filter('wp_new_user_notification_email', 'change_notification_message', 10, 3);

    function change_notification_message( $wp_new_user_notification_email, $user, $blogname ) {

        // Generate a new key
        $key = get_password_reset_key( $user );

        // Set the subject
        $wp_new_user_notification_email['subject'] = __('Your email subject');

        // Put the username in the message
        $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
        // Give your user the link to reset her password 
        $message .= __('To set your password, visit the following address:') . "\r\n\r\n";
        $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";

        $message .= wp_login_url() . "\r\n";

        // Set the email's message
        $wp_new_user_notification_email['message'] = $message;

        return $wp_new_user_notification_email;
    }
票数 6
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/316526

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档