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
<?php | |
/** | |
* Redirect users with 'foo' role to a specific page after login | |
* | |
* @since 1.0.0 | |
*/ | |
function ja_role_login_redirect( $redirect_to, $request, $user ){ | |
//is there a user to check? | |
if ( isset( $user->roles ) && is_array( $user->roles ) ) { | |
if( in_array( 'foo', $user->roles ) ) { | |
return site_url( 'foo-page' ); | |
} else { | |
return $redirect_to; | |
} | |
} | |
else { | |
return $redirect_to; | |
} | |
} | |
add_filter( 'login_redirect', 'ja_role_login_redirect', 10, 3 ); |
Questions, comments, or suggestion for improvement? Leave a comment on the GitHub Gist page.