我看不出“评论后更新”的答案是怎么回事。
“password\\u reset”钩子的文档中说“在重置用户密码之前触发”
如果重定向,则退出密码不会更改。
由于我有类似的需求,我制定了解决问题的方案。我们仍然会响应“password\\u reset”挂钩,但不是立即执行重定向,而是为“login\\u url”过滤器添加挂钩。在这个过滤器中,我们在用户登录后将重定向添加到主页。
add_action( "password_reset", "rngs_password_reset", 10, 2 );
/**
* Implement "password_reset" for RNGS
*
* After a password reset has been performed we want the Log in link to redirect the user to the home url.
* When we see this action being run we know that we should be filtering "login_url" to add the redirect the home page.
* We don\'t filter "login_url" any other time.
*
* @param WP_User $user - the user object
* @param string $new_pass - the new password
*
*/
function rngs_password_reset( $user, $new_pass ) {
add_filter( "login_url", "rngs_login_url", 10, 2 );
}
/**
* Implement "login_url" filter for RNGS
*
* Redirect the user to the home page after logging in
*
* @TODO - make this an option field that controls where the logged in user goes
* @TODO - dependent upon role?
*
* @param string $login_url - the original login_url which is not expected to include "redirect_to" or "reauth"
* @param string $redirect - expected to be null/blank
*/
function rngs_login_url( $login_url, $redirect ) {
$home_redirect = home_url();
$login_url = add_query_arg(\'redirect_to\', urlencode( $home_redirect ), $login_url);
return( $login_url );
}