Multisite: Default role to be Editor.

I'd like the default role to be Editor when a user registers for a new site in my network. I tried the following and it is giving 500. Any help, please.

function my_admin_to_editor($blog_id, $user_id) {
switch_to_blog($blog_id);
$user = new WP_User($user_id);
if ($user->exists()) {
$user->set_role('editor');
}
restore_current_blog();
}

add_action( 'wpmu_new_blog', 'my_admin_to_editor', 10, 2 );