I am working on a website with WordPress 3.7.1 and am trying to redirect the user upon login through the redirect_to URL parameter.
I checked that the redirect_to GET parameter sees the backend of the login form and that the login to the registration system includes the redirect_to POST value ... but this does not work.
Removed credentials for links and users
After logging in (both for my Admin acct and for the Subscriber subscriber specified in this message), the user goes to the WP control panel instead of the URL in the redirect_to parameter.
I have set allowed_redirect_hosts with the following code in a user plugin file (which is pretty much the same).
add_filter( 'allowed_redirect_hosts' , 'glue_allowed_redirect_hosts' , 10 ); function glue_allowed_redirect_hosts($content){ $content[] = 'app.realestategradschool.com'; $content[] = 'dev-app.realestategradschool.com'; $content[] = 'app.realestategradschool.local'; return $content; }
I disabled all other plugins trying to fix this problem.
Edit: I canβt use login_redirect because I donβt want to redirect all logins ... only if the visitor goes to the login page from another site (using oAuth to login ... oAuth works ... just not redirecting)
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 if(isset($_REQUEST['redirect_to'])){ $redirect_to = $_REQUEST['redirect_to']; } return $redirect_to; } add_filter('login_redirect','glue_login_redirect',999);
source share