Created
May 15, 2018 10:56
-
-
Save richerimage/d2f83135acbdbfdb9219f895f67f287d to your computer and use it in GitHub Desktop.
Redirect all but admin on login
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
add_filter('login_redirect', 'admin_login_redirect', 10, 3); | |
function admin_login_redirect( $redirect_to, $request, $user ) { | |
global $user; | |
if( isset( $user->roles ) && is_array( $user->roles ) ) { | |
if( in_array( 'administrator', $user->roles ) ) { | |
return $redirect_to; | |
} else { | |
return home_url(); | |
} | |
} else { | |
return $redirect_to; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment