function yakuphoca_login_redirect( $redirect_to, $request, $user ) {
if( $user && is_object( $user ) && is_a( $user, 'WP_User' ) ) {
if( $user->has_cap( 'edit_posts' ) ) {
$url = admin_url();
} else {
$url = home_url();
}
}
return $url;
}
add_filter( 'login_redirect', 'yakuphoca_login_redirect', 10, 3 );