登录后重定向,在Wordpress上注册并丢失密码到用户来自的原始页面


Redirect after Login, register and lost password on Wordpress to original page where users came from

我正在使用wordpress,我想在登录到wordpress后将重定向URL更改为用户登录的同一页面。目前我正在为登录用户使用此代码:

function admin_default_page() {
  return '/new-dashboard-url';
}
add_filter('login_redirect', 'admin_default_page');

我希望他们返回到登录时使用的同一页面,而不是 [new-dashboard-url]。怎么做?

注册和密码也是如此。

如果你想重定向到他们所在的最后一页,你可以尝试这样的事情:

add_filter('login_redirect', 'redirect_previous_page');
function redirect_previous_page(){
    return $_SERVER["HTTP_REFERER"];
}

似乎可以更容易地完成:

add_filter( 'login_redirect', 'wpse126853_redirect_to_request', 10, 3 );
function wpse126853_redirect_to_request( $redirect_to, $request, $user ) {
    // instead of using $redirect_to we're redirecting back to $request
    return $request;
}
if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) {
    add_filter('login_redirect', 'my_login_redirect', 10, 3);
    function my_login_redirect() {
        $location = $_SERVER['HTTP_REFERER'];
        wp_safe_redirect($location);
        exit();
    }
}