我使用WordPress v5.4.1,并有以下代码来从自定义页面发送密码重置邮件。
// Custom message
function replace_retrieve_password_message($message, $key, $user_login, $user_data) {
global $wpdb;
$key = $wpdb->get_var("SELECT user_activation_key FROM $wpdb->users WHERE user_login ='" . $user_login . "'");
if (empty($key)) {
//generate reset key
$key = wp_generate_password(20, false);
$wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
}
// Create new message
$msg = __('Hello!') . "\r\n\r\n";
$msg .= sprintf(__('You asked us to reset your password for your account using the email address %s.'), $user_login) . "\r\n\r\n";
$msg .= __("If this was a mistake, or you didn't ask for a password reset, just ignore this email and nothing will happen.") . "\r\n\r\n";
$msg .= __('To reset your password, visit the following address:') . "\r\n\r\n";
$msg .= site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . "\r\n\r\n";
$msg .= __('Thanks!') . "\r\n";
return $msg;
}
add_filter('retrieve_password_message', 'replace_retrieve_password_message', 10, 4);
用户收到密码重置邮件,但在单击链接时出现errors=invalidkey
错误。
我尝试删除自定义的$key
函数以使用WordPress默认密钥生成。这样我会有密码重置页面,但是任何操作都会显示errors = invalidkey
。