WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 3 months ago

#18743 new enhancement

Persistent redirect_to For Login, Registration, and Lost Password

Reported by: sparkweb Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.3
Component: Login and Registration Keywords:
Focuses: Cc:

Description

Currently, if redirect_to is passed in to the login screen and then a user clicks Register or Lost Password, the redirect_to gets lost. I think that the redirect_to should be persistent and honored whether the user logs in, registers or gets a lost password.

I've written a hacky filter to do this, but I think this ought to be included in the core. Here's what I did:

//Keep redirect_to in URL
add_filter('site_url', 'foxyshop_add_registration_redirect', 5);
function foxyshop_add_registration_redirect($path) {
	if ((strpos($path, "action=register") !== false || strpos($path, "action=lostpassword") !== false) && isset($_REQUEST['redirect_to'])) return $path . '&redirect_to='.urlencode($_REQUEST['redirect_to']);
	if (substr($path, strlen($path)-12) == "wp-login.php" && isset($_REQUEST['redirect_to'])) return $path . '?redirect_to='.urlencode($_REQUEST['redirect_to']);
	return $path;
}

(I know 3.3 is in freeze now, but there wasn't another version option)

Change History (4)

comment:1 kawauso3 years ago

The Version is for the earliest version affected by the issue, rather than the one you want it fixed in.

comment:2 SergeyBiryukov14 months ago

#23523 was marked as a duplicate.

comment:3 onokazu11 months ago

Maybe the following line in wp-login.php (line 709 in WP 3.5.1)

<a href="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login' ) ); ?>"><?php _e( 'Register' ); ?></a> |

should be

<a href="<?php echo esc_url( site_url( 'wp-login.php?action=register&' . urlencode($redirect_to), 'login' ) ); ?>"><?php _e( 'Register' ); ?></a> |
Last edited 11 months ago by onokazu (previous) (diff)

comment:4 jeremyfelt3 months ago

  • Component changed from Users to Login and Registration
Note: See TracTickets for help on using tickets.