Created
March 1, 2017 19:12
-
-
Save mojenmojen/8fb362986bc22b1c5be7f0e34f3a1b60 to your computer and use it in GitHub Desktop.
WordPress Login Redirect
This file contains 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 after successful login. | |
* | |
* @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 | |
*/ | |
function qs_login_redirect( $redirect_to, $request, $user ) { | |
//is there a user to check? | |
if ( isset( $user->roles ) && is_array( $user->roles ) ) { | |
//check for admins | |
if ( in_array( 'administrator', $user->roles ) ) { | |
// redirect them to the default place | |
return $redirect_to; | |
} else { | |
return home_url('my-quiet-self'); | |
} | |
} else { | |
return $redirect_to; | |
} | |
} | |
add_filter( 'login_redirect', 'qs_login_redirect', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment