Login Redirect Based on User Role

<?php
// login redirects
function wd_admin_login_redirect( $redirect_to, $request, $user ) {
     global $user;

     if( isset( $user->roles ) && is_array( $user->roles ) ) {
          if( in_array( 'administrator', $user->roles ) ) {
               return $redirect_to;
          } elseif( in_array( 'editor', $user->roles ) ) {
               return $redirect_to;
          } else {
               return $redirect_to;
          }
     } else {
          return $redirect_to;
     }
}
add_filter( 'login_redirect', 'wd_admin_login_redirect', 10, 3);