Adam Erstelle Adam Erstelle - 1 year ago 128
PHP Question

WordPress Login redirect_to not working

I'm working on a web site with WordPress 3.7.1 and trying to redirect a user upon login via the redirect_to URL parameter.

I've verified that the login form backend sees the redirect_to GET parameter, and that the login submission includes the redirect_to POST value...but thats where things don't work.

Removed link and user credentials

Upon login (for both my Admin acct and the Subscriber acct provided in this post), the user is taken to the WP dashboard instead of the URL in the redirect_to parameter.

I do have the allowed_redirect_hosts being set, with the following code in a custom plugin file (which is pretty much just this).

add_filter( 'allowed_redirect_hosts' , 'glue_allowed_redirect_hosts' , 10 );
function glue_allowed_redirect_hosts($content){
$content[] = '';
$content[] = '';
$content[] = 'app.realestategradschool.local';
return $content;

I've disabled all other plugins in an attempt to troubleshoot this.

Edit: I can't use login_redirect as I'm not looking to redirect ALL logins...only if the visitor is sent to the login page from a different site (using oAuth to log them in...oAuth works...just not the redirect)

Edit: Working solution:

function glue_login_redirect($redirect_to,$request='',$user=null){
//using $_REQUEST because when the login form is submitted the value is in the POST
$redirect_to = $_REQUEST['redirect_to'];
return $redirect_to;

Answer Source

You can use login_redirect filter. See here

I think this is what you are looking for.

This will normally redirect all logins. To be able to redirect only when you want, you can use a query string parameter in the URL. Check for the parameter, if it exists redirect.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download