WordPress Redirect Page After Login

In this WordPress post, i added the source code to redirect the page after the log in like simple redirect plugin. I would like to give the access of admin panel for "administrator" and "editor" roles of WordPress user. Otherwise i am redirecting the user to home page. You can modify redirect URL after login. I allowed administrator and editor to access the admin section and denied the permission for contributor, author and subscriber. [gad]

Wordpress Login Redirect Function


function bsc_login_redirect( $default_redirect_url, $request, $user ){
    global $user;
    if( isset( $user->roles ) && is_array( $user->roles ) ) {
        //check and allow the administrator and editor users
        if( in_array( "administrator", $user->roles ) || in_array( "editor", $user->roles ) )         {
            return $default_redirect_url;
        } else {
            return home_url();
        }
    }
    else {
        return $default_redirect_url;
    }
}
add_filter("login_redirect", "bsc_login_redirect", 10, 3);