[英]WordPress logout after password change “something went wrong” message
I use a form and the wp_update_user function to let users change their password in the WordPress frontend. 我使用表单和wp_update_user函数让用户在WordPress前端中更改密码。 For this i use an ajax function which executes wp_update_user: 为此,我使用一个执行wp_update_user的ajax函数:
/* CHANGE PASSWORD OF USER */
if ( !empty($pass1 ) && !empty( $pass2 ) ) {
if ( $pass1 == $pass2 ) {
wp_update_user( array( 'ID' => $userID, 'user_pass' => esc_attr( $pass2 ) ) );
echo "<div class='message-hub-success'>Passsword changed!</div>";
} else {
echo "<div class='message-hub-error'>The passwords you entered do not match. Your password was not updated.</div>";
}
}
The password change is working as expected. 密码更改按预期工作。 But when the user clicks the logout-link after the password change i get the error "something went wrong" instead of a the logout and the redirect function. 但是,当用户在更改密码后单击注销链接时,出现错误“出了点问题”,而不是注销和重定向功能。 My logout link: 我的注销链接:
<a href="<?php echo wp_logout_url( home_url() ); ?>">Logout</a>
The something went wrong message is not shown on the page but on a wordpress page with a logout link: 出问题的消息未显示在页面上,但在带有注销链接的wordpress页面上:
The reason is that when you update the password, the user's cookies are cleared (see the documentation for wp_update_user ). 原因是,当您更新密码时,将清除用户的cookie(请参阅wp_update_user的文档)。
Then, during logout, the user's session is not available, which causes the issue you are experiencing. 然后,在注销过程中,用户会话不可用,这会导致您遇到问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.