-
-
Save CodeCurosity/e834b5b6c82bca1d820d5d177a56d85a to your computer and use it in GitHub Desktop.
WordPress function for redirecting users on login based on user role
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
<?php | |
/** | |
* WordPress function for redirecting users on login based on user role | |
*/ | |
function my_login_redirect( $url, $request, $user ){ | |
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) { | |
if( $user->has_cap( 'administrator' ) ) { | |
$url = admin_url(); | |
} else { | |
$url = home_url('/members-only/'); | |
} | |
} | |
return $url; | |
} | |
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