Make WordPress Core

Opened 13 years ago

Last modified 5 years ago

#18743 new enhancement

Persistent redirect_to For Login, Registration, and Lost Password

Reported by: sparkweb's profile sparkweb Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3
Component: Login and Registration Keywords: needs-patch
Focuses: Cc:


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)

Attachments (1)

general-template.php.patch (910 bytes) - added by ross_ritchey 7 years ago.
Add redirect handling to wp_registration_url

Download all attachments as: .zip

Change History (8)

#1 @kawauso
13 years ago

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

#2 @SergeyBiryukov
11 years ago

#23523 was marked as a duplicate.

#3 @onokazu
11 years 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 years ago by onokazu (previous) (diff)

#4 @jeremyfelt
10 years ago

  • Component changed from Users to Login and Registration

This ticket was mentioned in IRC in #wordpress-dev by rmccue. View the logs.

10 years ago

#6 @chriscct7
8 years ago

  • Keywords needs-patch added

Good First Bug: Attempt to replicate

7 years ago

Add redirect handling to wp_registration_url

#7 @ross_ritchey
7 years ago

Just added a partial patch for this.

Looking at things it seems that the Forgot Password link handling already has the logic for passing the redirect through -> though need to test and confirm that this is working as intended.

I added handling to wp_registration_url() to allow for passing a redirect url in (the same way all of the other login-related url functions are working).

What is still needed is to go through the remaining core pieces of the login process and update things to properly pass the redirect through to this function.

Note: See TracTickets for help on using tickets.