admin管理员组文章数量:1434187
I am trying create passowrd reset form. Here is my function:
<?php
$user_data = get_user_by( 'email', '[email protected]' ) );
$key = get_password_reset_key( $user_data );
$user_login = $user_data->user_login;
$message = esc_url( get_permalink( '1' ) . "?action=rp&key=$key&login=" . rawurlencode($user_login) ) . "\r\n";
wp_mail( $user_email, "Title", $message );
?>
It sends reset link to my mail, with $key and $login. It is ok.
Now i must check the reset key. Here is my code:
<?php
$errors = new WP_Error();
$user = check_password_reset_key($_GET['key'], $_GET['login']);
if ( is_wp_error( $user ) ) {
if ( $user->get_error_code() === 'expired_key' )
echo "Key is expired";
else
echo "Key is not valid";
}
?>
But it always says Key is not valid. Where is wrong?
I am trying create passowrd reset form. Here is my function:
<?php
$user_data = get_user_by( 'email', '[email protected]' ) );
$key = get_password_reset_key( $user_data );
$user_login = $user_data->user_login;
$message = esc_url( get_permalink( '1' ) . "?action=rp&key=$key&login=" . rawurlencode($user_login) ) . "\r\n";
wp_mail( $user_email, "Title", $message );
?>
It sends reset link to my mail, with $key and $login. It is ok.
Now i must check the reset key. Here is my code:
<?php
$errors = new WP_Error();
$user = check_password_reset_key($_GET['key'], $_GET['login']);
if ( is_wp_error( $user ) ) {
if ( $user->get_error_code() === 'expired_key' )
echo "Key is expired";
else
echo "Key is not valid";
}
?>
But it always says Key is not valid. Where is wrong?
Share Improve this question asked Feb 25, 2018 at 22:19 wpdevwpdev 5492 gold badges13 silver badges28 bronze badges 5 |1 Answer
Reset to default 2I fixed it. We need decode url with esc_url_raw. Here is solution.
<?php
$user_data = get_user_by( 'email', '[email protected]' ) );
$key = get_password_reset_key( $user_data );
$user_login = $user_data->user_login;
$url = esc_url_raw( get_permalink( '1' ) . "?action=rp&key=$key&login=" . rawurlencode($user_login) ) . "\r\n";
$message = $url;
wp_mail( $user_email, "Title", $message );
?>
本文标签: Check Password Reset Key Not Woking
版权声明:本文标题:Check Password Reset Key Not Woking 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745609702a2666042.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
else
, try toecho
the$user->get_error_message()
instead of "Key is not valid", and see what it says. – Sally CJ Commented Feb 26, 2018 at 7:09$user = check_password_reset_key($_GET['key'], rawurldecode($_GET['login']));
because yourawurlencode()
thelogin
in the email. If that doesn't work, dovar_dump( $_GET['key'], $_GET['login'] );
and see if the values are valid. – Sally CJ Commented Feb 26, 2018 at 17:39esc_url()
works. I.e. By default, it converts&
to&
. Sorry that I didn't really notice (or pay attention to) thewp_mail()
part. =) – Sally CJ Commented Feb 26, 2018 at 19:32