src/OwpUsers.inc.php
public function addUser($data_array)
    {

        $required_columns = array(
            "email",
            "passwd",
            "first_name",
            "last_name",
            "statusID",
            "welcome_email_sent",
        );

        $missing_columns = array_diff($required_columns, array_keys($data_array));

        if ($missing_columns) {
            throw new Exception("The following columns are missing: " . implode(", ", $missing_columns));
        }

        // Execute owpUDF_On_addUserValiateData user defined function
        if (function_exists("owpUDF_On_addUserValiateData")) {
            $owpUDF_On_addUserValiateData = owpUDF_On_addUserValiateData(array("db" => $this->OwpDBMySQLi, "data_array" => $data_array));
            if ($owpUDF_On_addUserValiateData) {
                throw new Exception($owpUDF_On_addUserValiateData, 30);
            }
        }

        $validator = new EmailValidator();
        $multipleValidations = new MultipleValidationWithAnd(
            [
                new RFCValidation(),
                new DNSCheckValidation(),
                new SpoofCheckValidation()
            ]
        );

        if (!$validator->isValid($data_array["email"], $multipleValidations)) {
            throw new Exception("Invalid Email: " . (string)$data_array["email"]);
        }

        if (!self::validateStatusID((int)$data_array["statusID"])) {
            throw new Exception("Invalid statusID: " . (int)$data_array["statusID"]);
        }

        if (isset($data_array["user_created_datetime"])) {
            unset($data_array["user_created_datetime"]);
        }

        if (isset($data_array["user_updated_datetime"])) {
            unset($data_array["user_updated_datetime"]);
        }

        if (isset($data_array["user_last_login_datetime"])) {
            unset($data_array["user_last_login_datetime"]);
        }

        if (isset($data_array["reset_pass_uuid"])) {
            unset($data_array["reset_pass_uuid"]);
        }

        if (isset($data_array["user_ip"])) {
            unset($data_array["user_ip"]);
        }

        if (isset($data_array["userID"])) {
            unset($data_array["userID"]);
        }

        $new_hash = $this->genPasswdHash($data_array["passwd"]);

        $query_sql = "
            INSERT INTO tbl_users
            SET tbl_users.email = LCASE('" . filter_var($data_array["email"], FILTER_SANITIZE_EMAIL) . "'),
                tbl_users.passwd = '" . (string)$new_hash . "',
                tbl_users.first_name = '" . $this->OwpDBMySQLi->escape($data_array["first_name"]) . "',
                tbl_users.last_name = '" . $this->OwpDBMySQLi->escape($data_array["last_name"]) . "',
                tbl_users.statusID = " . (int)$data_array["statusID"] . ",
                tbl_users.user_created_datetime = SYSDATE(),
                tbl_users.user_updated_datetime = SYSDATE(),
                tbl_users.user_last_login_datetime = SYSDATE(),
                tbl_users.login_count = 0,
                tbl_users.welcome_email_sent = " . (int)$data_array["welcome_email_sent"] . ",
                tbl_users.uuid = '" . OwpSupportMethods::uuid() . "',
                tbl_users.reset_pass_uuid = NULL,
                tbl_users.user_ip = NULL";

        $this->userID = ($this->OwpDBMySQLi->query($query_sql) ? (int)$this->OwpDBMySQLi->insert_id : false);

        if (!$this->userID) {
            throw new Exception("Insert tbl_users failed: " . $this->OwpDBMySQLi->last_error, 10);
        }

        $query_sql = "
            SELECT * FROM tbl_users WHERE tbl_users.userID = " . (int)$this->userID . " LIMIT 1
        ";

        $current_user_row = $this->OwpDBMySQLi->get_row($query_sql, ARRAY_A);

        if (!$current_user_row) {
            throw new Exception("Get user failed: " . $this->OwpDBMySQLi->MySQLFirephpGetLastMysqlError(), 10);
        }

        $core_keys = $current_user_row;
        unset($core_keys["userID"]);
        $meta_keys = array_diff_key($data_array, $current_user_row);

        if ($meta_keys && is_array($meta_keys)) {
            foreach ($meta_keys as $dk => $dv) {
                $query_sql = "
                    REPLACE INTO tbl_users_meta_data
                    SET
                        tbl_users_meta_data.key_name = '" . (string)$dk . "',
                        tbl_users_meta_data.key_value = '" . (string)$this->OwpDBMySQLi->escape($dv) . "',
                        tbl_users_meta_data.userID = " . (int)$this->userID . ",
                        tbl_users_meta_data.updated_ts = SYSDATE()";

                $this->OwpDBMySQLi->query($query_sql);
            }
        }

        // Execute owpUDF_On_addUserSuccess user defined function
        if (function_exists("owpUDF_On_addUserSuccess")) {
            $owpUDF_On_addUserSuccess = owpUDF_On_addUserSuccess(array("userID" => (int)$this->userID, "db" => $this->OwpDBMySQLi));
            if ($owpUDF_On_addUserSuccess) {
                throw new Exception((string)$owpUDF_On_addUserSuccess, 30);
            }
        }

        return (int)$this->userID;

    }
public function addUser($data_array)
    {

        $required_columns = array(
            "email",
            "passwd",
            "first_name",
            "last_name",
            "statusID",
            "welcome_email_sent",
        );

        $missing_columns = array_diff($required_columns, array_keys($data_array));

        if ($missing_columns) {
            throw new Exception("The following columns are missing: " . implode(", ", $missing_columns));
        }

        // Execute owpUDF_On_addUserValiateData user defined function
        if (function_exists("owpUDF_On_addUserValiateData")) {
            $owpUDF_On_addUserValiateData = owpUDF_On_addUserValiateData(array("db" => $this->OwpDBMySQLi, "data_array" => $data_array));
            if ($owpUDF_On_addUserValiateData) {
                throw new Exception($owpUDF_On_addUserValiateData, 30);
            }
        }

        $validator = new EmailValidator();
        $multipleValidations = new MultipleValidationWithAnd(
            [
                new RFCValidation(),
                new DNSCheckValidation(),
                new SpoofCheckValidation()
            ]
        );

        if (!$validator->isValid($data_array["email"], $multipleValidations)) {
            throw new Exception("Invalid Email: " . (string)$data_array["email"]);
        }

        if (!self::validateStatusID((int)$data_array["statusID"])) {
            throw new Exception("Invalid statusID: " . (int)$data_array["statusID"]);
        }

        if (isset($data_array["user_created_datetime"])) {
            unset($data_array["user_created_datetime"]);
        }

        if (isset($data_array["user_updated_datetime"])) {
            unset($data_array["user_updated_datetime"]);
        }

        if (isset($data_array["user_last_login_datetime"])) {
            unset($data_array["user_last_login_datetime"]);
        }

        if (isset($data_array["reset_pass_uuid"])) {
            unset($data_array["reset_pass_uuid"]);
        }

        if (isset($data_array["user_ip"])) {
            unset($data_array["user_ip"]);
        }

        if (isset($data_array["userID"])) {
            unset($data_array["userID"]);
        }

        $new_hash = $this->genPasswdHash($data_array["passwd"]);

        $query_sql = "
            INSERT INTO tbl_users
            SET tbl_users.email = LCASE('" . filter_var($data_array["email"], FILTER_SANITIZE_EMAIL) . "'),
                tbl_users.passwd = '" . (string)$new_hash . "',
                tbl_users.first_name = '" . $this->OwpDBMySQLi->escape($data_array["first_name"]) . "',
                tbl_users.last_name = '" . $this->OwpDBMySQLi->escape($data_array["last_name"]) . "',
                tbl_users.statusID = " . (int)$data_array["statusID"] . ",
                tbl_users.user_created_datetime = SYSDATE(),
                tbl_users.user_updated_datetime = SYSDATE(),
                tbl_users.user_last_login_datetime = SYSDATE(),
                tbl_users.login_count = 0,
                tbl_users.welcome_email_sent = " . (int)$data_array["welcome_email_sent"] . ",
                tbl_users.uuid = '" . OwpSupportMethods::uuid() . "',
                tbl_users.reset_pass_uuid = NULL,
                tbl_users.user_ip = NULL";

        $this->userID = ($this->OwpDBMySQLi->query($query_sql) ? (int)$this->OwpDBMySQLi->insert_id : false);

        if (!$this->userID) {
            throw new Exception("Insert tbl_users failed: " . $this->OwpDBMySQLi->last_error, 10);
        }

        $query_sql = "
            SELECT * FROM tbl_users WHERE tbl_users.userID = " . (int)$this->userID . " LIMIT 1
        ";

        $current_user_row = $this->OwpDBMySQLi->get_row($query_sql, ARRAY_A);

        if (!$current_user_row) {
            throw new Exception("Get user failed: " . $this->OwpDBMySQLi->MySQLFirephpGetLastMysqlError(), 10);
        }

        $core_keys = $current_user_row;
        unset($core_keys["userID"]);
        $meta_keys = array_diff_key($data_array, $current_user_row);

        if ($meta_keys && is_array($meta_keys)) {
            foreach ($meta_keys as $dk => $dv) {
                $query_sql = "
                    REPLACE INTO tbl_users_meta_data
                    SET
                        tbl_users_meta_data.key_name = '" . (string)$dk . "',
                        tbl_users_meta_data.key_value = '" . (string)$this->OwpDBMySQLi->escape($dv) . "',
                        tbl_users_meta_data.userID = " . (int)$this->userID . ",
                        tbl_users_meta_data.updated_ts = SYSDATE()";

                $this->OwpDBMySQLi->query($query_sql);
            }
        }

        // Execute owpUDF_On_addUserSuccess user defined function
        if (function_exists("owpUDF_On_addUserSuccess")) {
            $owpUDF_On_addUserSuccess = owpUDF_On_addUserSuccess(array("userID" => (int)$this->userID, "db" => $this->OwpDBMySQLi));
            if ($owpUDF_On_addUserSuccess) {
                throw new Exception((string)$owpUDF_On_addUserSuccess, 30);
            }
        }

        return (int)$this->userID;

    }
addUser

@method integer addUser($data_array) Create a user record
@access public

@param array $data_array User array used to create the user's record. ("email", "passwd", "first_name", "last_name", "statusID", "welcome_email_sent", "uuid")

@return integer userID

@throws InvalidArgumentException Thrown when the provided argument is not valid user data, code 20
@throws Exception Thrown on standard failures, code 10, UDF failures code 30

@author  Brian Tafoya <btafoya@briantafoya.com>
@version 1.0