워드프레스 로그인 후 페이지 이동 – user role redirect

  • 03 / 01 / 2016
  • by wpresso
  • 0 reply

[php]
/**
* 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;
if ( isset( $user->roles ) && is_array( $user->roles ) ) {
//check for admins
if ( in_array( ‘administrator, editor, contributor, author’, $user->roles ) ) {
// redirect them to the default place
return $redirect_to;
} else {
return home_url();
}
} else {
return $redirect_to;
}
}

add_filter( ‘login_redirect’, ‘my_login_redirect’, 10, 3 );
[/php]