blocking access to wp admin area

I need to find away to prevent users from accessing the wp-admin area i used this code

add_action( 'init', 'blockusers_init' );

function blockusers_init() {
if ( is_admin() && ! current_user_can( 'administrator' ) &&
! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}

How ever this prevented users from being able to add images to there media library which I users to be able to do