WordPress login redirect_to not working

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); 
+6
source share
3 answers

You can use the login_redirect filter. Take a look here http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

I think this is what you are looking for.

Usually this redirects all logins. To be able to redirect only when you want, you can use the query string parameter in the url. Check the parameter, if it exists, redirects.

+7
source

Try adding this to your functions.php file in your template:

 add_action( 'login_form' , 'glue_login_redirect' ); function glue_login_redirect() { global $redirect_to; if (!isset($_GET['redirect_to'])) { $redirect_to = 'YOURURLHERE'; } else{ $redirect_to = $_GET['redirect_to']; } } 
+1
source

Perhaps this code will help you.

 <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" /> 

Redirects users to where you are coming from. example. if you log in from the home page or message. His login then redirects back to the main page or login page.

This main part of the code:

 <?php echo $_SERVER['REQUEST_URI']; ?> 
0
source

Source: https://habr.com/ru/post/959259/


All Articles