Features – Why does not get_user_by () work in my code?

I'm editing the code of a plugin to add a little functionality that I need.
I almost made it, but I really have trouble and I do not understand why

$ user_id_for_um_groups = get_user_by (& # 39; email & # 39 ;, $ email);

does not work here and I get 0 in the user_id2 column of my database (I need to get the user ID).

I enclose the full code below, my added code is commented as ADD CODE.

I would be very grateful for your help as I have spent several days understanding why it does not work. Thank you very much 😉

 $email ) {
                if ( ! empty( $email ) ) {
                    if ( is_email( $email ) ) {
                        $first       = $first_names( $k );
                        $last        = $last_names( $k );
                        $email       = sanitize_email( $email );
                        $is_existing = email_exists( $email );

                        if ( is_numeric( $is_existing ) ) {
                            $user_id     = $is_existing;
                            $user_groups = learndash_get_users_group_ids( $user_id, true );
                            if ( in_array( $group_id, $user_groups ) ) {
                                $error_results() = sprintf( __( 'Line #%d: %s is existing user of group.', 'uncanny-learndash-groups' ), $k + 1, $email );
                                continue;
                            }
                            $user_data = array(
                                'user_email' => $email,
                                'user_id'    => $user_id,
                                'first_name' => $first,
                                'last_name'  => $last,
                                'role'       => $role,
                            );

                            if ( isset( $user_data('first_name') ) && ! $is_existing ) {
                                update_user_meta( $user_id, 'first_name', $user_data('first_name') );
                            }

                            if ( isset( $user_data('last_name') ) && ! $is_existing ) {
                                update_user_meta( $user_id, 'last_name', $user_data('last_name') );
                            }

                            $restApi = new RestApiEndPoints();
                            $restApi->add_existing_user( $user_data, false, $group_id, 0, 'not redeemed', false );

                        } else {
                            $user_data = array(
                                'user_login' => $email,
                                'user_email' => $email,
                                'first_name' => $first,
                                'last_name'  => $last,
                                'role'       => $role,
                                'group_id'   => $group_id,
                            );
                            $restApi   = new RestApiEndPoints();
                            $restApi->add_invite_user( $user_data, false, false, false );

                        }
                        $insert_results() = sprintf( __( '%s added & invited successfully.', 'uncanny-learndash-groups' ), $email );

                    //ADDED CODE
                     global $wpdb;

                     $user_id_for_um_groups = get_user_by( 'email', $email );

                     $current_group_id_for_um_groups = $wpdb->get_var("SELECT ID FROM wpso_posts WHERE post_excerpt = $group_id");
                     $current_user_id_for_um_groups = get_current_user_id();
                     $wpdb->insert( 'wpso_um_groups_members', array( 
                     'group_id' => $current_group_id_for_um_groups,
                     'user_id1' => $user_id_for_um_groups,
                     'user_id2' => $current_user_id_for_um_groups,
                     'status' => 'approved',
                     'role' => 'member') );
                    //END OF ADDED CODE

                    } else {
                        $error_results() = sprintf( __( 'Line #%d: Email (%s) not correct.', 'uncanny-learndash-groups' ), $k + 1, $email );
                    }
                } else {
                    if ( ! empty( $first_names( $k ) ) || ! empty( $last_names( $k ) ) ) {
                        $error_results() = sprintf( __( 'Line #%d: Email field is empty.', 'uncanny-learndash-groups' ), $k + 1 );
                    }
                }
            }
        }
        $url = SharedFunctions::get_group_management_page_id( true );
        $url .= '?group-id=' . $group_id;
        $url .= '&bulk=1';
        if ( ! empty( $error_results ) ) {
            $url .= '&bulk-errors=' . urlencode( join( '
', $error_results ) ); } if ( ! empty( $insert_results ) ) { $url .= '&success-invited=' . urlencode( join( '
', $insert_results ) ); } wp_safe_redirect( $url ); exit; } }