Skip to content

Instantly share code, notes, and snippets.

@ahmadawais
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadawais/302c2bbe79b9aebf8cc4 to your computer and use it in GitHub Desktop.
Save ahmadawais/302c2bbe79b9aebf8cc4 to your computer and use it in GitHub Desktop.
WordPress Login Redirect
/** Login Redirect
* 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 my_login_redirect( $redirect_to, $request, $user ) {
//is there a user to check?
global $user;
global $current_user;
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( 'administrator', $user->roles ) ) {
// redirect them to the default place
return home_url('/wp-admin/');
}
else {
return home_url('/dashboard/');
// home_url('/dashboard/'.$user->user_login.'/');
}
} else {
return $redirect_to;
}
}
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment