我试图定制发送给新注册用户的电子邮件。我在插件中使用了wp_new_user_notification_email过滤器,它可以很好地设置主题和消息。然而,I希望发送链接来重置用户的密码,就像普通WP通知电子邮件所做的一样。
根据我在wp_new_user_notification函数中所看到的,在存储在数据库中之前,哈希中的密码密钥。然后在url中使用此键重置密码。问题是,我不能在我用wp_new_user_notification_email过滤器调用的函数中访问这个变量,如果我生成一个放进url的randow键,就会在表单中抛出一个错误(可能是因为新键不对应于存储的散列键)。
我想有一种方法可以实现这一点,因为有一个过滤器来自定义注册消息,而不给予重新设置密码的链接将是非常没有意义的。
知道吗?
发布于 2018-10-12 09:59:41
我找到了一个函数来检索这个键: get_password_reset_key()。
现在,我的插件中有了以下代码,用于自定义发送给新注册用户的电子邮件:
    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;
    }https://wordpress.stackexchange.com/questions/316526
复制相似问题