Saya masih mengalami masalah dengan kunci reset tidak berfungsi dengan benar, tautan dalam email akan mengarahkan saya ke halaman reset kata sandi standar dengan parameter URL yang menunjukkan masalah dengan kunci, jadi saya lebih dekat mengikuti file wp-login.php dan termasuk objek $ wp_hasher, ini memperbaiki masalah dan pengaturan ulang kata sandi dalam email sekarang berfungsi
if (($_SERVER['REQUEST_METHOD'] === (string) 'POST') && (isset($_POST['reset_pass']))) {
// Acccess global properties
global $wpdb, $wp_hasher;
// Variables
$error_pass_reset = array();
$username = (string) trim($_POST['user_login']);
$user_exists = (bool) false;
// ---- USERNAME OR EMAIL EXISTS ---- //
if (username_exists($username)) {
$user_exists = (bool) true;
$user = (object) get_user_by('login', $username);
} // end if
else if (email_exists($username)) {
$user_exists = (bool) true;
$user = (object) get_user_by('email', $username);
} // end else if
else {
$error_pass_reset[] = '<p>Username or Email was not found, please try again.</p>';
} // end else
// ---- USER EXISTS ---- //
if ($user_exists === (bool) true) {
// Variables
$user_login = (string) $user -> user_login;
$user_email = (string) $user -> user_email;
// Generate password reset key
if (empty($key)) {
$key = (string) wp_generate_password(20, false);
do_action('retrieve_password_key', $user_login, $key);
// Create the $wp_hasher object
if (empty($wp_hasher)) {
require_once(ABSPATH . WPINC . '/class-phpass.php');
$wp_hasher = new PasswordHash(8, true);
}
// Reset key with hasher applied (MD5 has string output)
$hashed = (string) time() . ':' . $wp_hasher -> HashPassword($key);
// Insert the new key into the database
$wpdb -> update(
$wpdb -> users,
array(
'user_activation_key' => $hashed
),
array(
'user_login' => $user_login
)
);
} // end if
// Email message
$message = (string)
'Someone requested that the password be reset for the following account:' . "\r\n\r\n" .
get_option('siteurl') . "\r\n\r\n" .
'Username: ' . $user_login . "\r\n\r\n" .
'If this was a mistake, just ignore this email and nothing will happen.' . "\r\n\r\n" .
'To reset your password, visit the following address:' . "\r\n\r\n" .
get_option('siteurl') . '/wp-login.php?action=rp&key=' . $key . '&login=' . $user_login . "\r\n";
// Send email
if ((bool) false === wp_mail($user_email, get_option('blogname') . ' Password Reset', $message)) {
$error_pass_reset[] = '<p>The e-mail could not be sent at this time.</p>' . "\n";
} // end if
} // end if
// Send the rest password email
do_action('login_form', 'resetpass');
} // end if (($_SERVER['REQUEST_METHOD'] === (string) 'POST') && (isset($_POST['reset_pass'])))
username_exists()
Anda membantu?