Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created May 24, 2013 01:02
Show Gist options
  • Save jaredatch/5640656 to your computer and use it in GitHub Desktop.
Save jaredatch/5640656 to your computer and use it in GitHub Desktop.
Redirect users with a certain role to a specific page after login
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment