Last active
August 5, 2020 19:08
-
-
Save rali14/85b0b2cc97c6122704e7bb21593fbcf8 to your computer and use it in GitHub Desktop.
Redirect user to a specific URL if logged in from another specific URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Redirect user to a specific URL if logged in from another specific URL | |
* | |
* @param string $redirect_to URL to redirect to. | |
* @param string $request URL the user is coming from. | |
* @param object $user Logged user's data. | |
* @return string | |
* | |
* Author: Rashid - https://w3plus.ca | |
*/ | |
function w3_login_redirect( $redirect_to, $request, $user ) { | |
// This is the URL that the user is coming from | |
$fromURL = "https://w3plus.ca/about-us/"; | |
// This is the URL the user will be redirected to | |
$toURL = "https://w3plus.ca/contact-us/"; | |
// Here is where we do the checks | |
if ( $request == $fromURL ) { | |
return $toURL; | |
} else { | |
// Otherwise do the default | |
return $redirect_to; | |
} | |
} | |
add_filter( 'login_redirect', 'w3_login_redirect', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment