src/OwpUsers.inc.php
public function updateUser($userID, $data_array)
    {

        if (!(int)$userID) {
            $this->errors[] = array(
                "message" => "updateUser: Invalid userID.",
                "details" => array("userID" => (int)$userID),
            );

            throw new InvalidArgumentException("Invalid userID " . (int)$userID, 10);
        }

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

        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_ip"])) {
            unset($data_array["user_ip"]);
        }

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

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

        if (!$current_user_row) {
            $this->errors[] = array(
                "message" => "updateUser: current_user_row SELECT tbl_users failed.",
                "details" => array(
                    "query_sql" => $query_sql,
                    "last_mysql_error" => $this->OwpDBMySQLi->MySQLFirephpGetLastMysqlError(),
                ),
            );

            throw new InvalidArgumentException("Invalid userID " . (int)$userID, 10);
        }

        unset($current_user_row["user_created_datetime"]);
        unset($current_user_row["user_updated_datetime"]);
        unset($current_user_row["passwd"]);

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

        $ck_sql_array = array();
        if ($core_keys) {
            foreach ($core_keys as $ckc => $ckv) {
                if (isset($data_array[$ckc]) && $data_array[$ckc] != $ckv) {
                    $ck_sql_array[] = " `tbl_users`.`" . (string)$ckc . "` = '" . $this->OwpDBMySQLi->escape((string)$data_array[$ckc]) . "' ";
                }
            }
        }

        $ck_sql_array[] = " `tbl_users`.`user_updated_datetime` = SYSDATE() ";

        $setStatement = implode(", ", $ck_sql_array);

        $query_sql = "
                UPDATE tbl_users
                SET " . $setStatement . "
                WHERE tbl_users.userID = " . (int)$userID . "
            LIMIT 1";

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

        $meta_key_exclude = array(
            "full_name",
            "hide_ads",
            "is_admin",
            "is_dev"
        );

        if ($meta_keys && is_array($meta_keys)) {
            foreach ($meta_keys as $dk => $dv) {
                if (!in_array($dk, $meta_key_exclude)) {
                    $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)$userID . ",
                        tbl_users_meta_data.updated_ts = SYSDATE()";

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

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

        return true;

    }
public function updateUser($userID, $data_array)
    {

        if (!(int)$userID) {
            $this->errors[] = array(
                "message" => "updateUser: Invalid userID.",
                "details" => array("userID" => (int)$userID),
            );

            throw new InvalidArgumentException("Invalid userID " . (int)$userID, 10);
        }

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

        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_ip"])) {
            unset($data_array["user_ip"]);
        }

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

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

        if (!$current_user_row) {
            $this->errors[] = array(
                "message" => "updateUser: current_user_row SELECT tbl_users failed.",
                "details" => array(
                    "query_sql" => $query_sql,
                    "last_mysql_error" => $this->OwpDBMySQLi->MySQLFirephpGetLastMysqlError(),
                ),
            );

            throw new InvalidArgumentException("Invalid userID " . (int)$userID, 10);
        }

        unset($current_user_row["user_created_datetime"]);
        unset($current_user_row["user_updated_datetime"]);
        unset($current_user_row["passwd"]);

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

        $ck_sql_array = array();
        if ($core_keys) {
            foreach ($core_keys as $ckc => $ckv) {
                if (isset($data_array[$ckc]) && $data_array[$ckc] != $ckv) {
                    $ck_sql_array[] = " `tbl_users`.`" . (string)$ckc . "` = '" . $this->OwpDBMySQLi->escape((string)$data_array[$ckc]) . "' ";
                }
            }
        }

        $ck_sql_array[] = " `tbl_users`.`user_updated_datetime` = SYSDATE() ";

        $setStatement = implode(", ", $ck_sql_array);

        $query_sql = "
                UPDATE tbl_users
                SET " . $setStatement . "
                WHERE tbl_users.userID = " . (int)$userID . "
            LIMIT 1";

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

        $meta_key_exclude = array(
            "full_name",
            "hide_ads",
            "is_admin",
            "is_dev"
        );

        if ($meta_keys && is_array($meta_keys)) {
            foreach ($meta_keys as $dk => $dv) {
                if (!in_array($dk, $meta_key_exclude)) {
                    $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)$userID . ",
                        tbl_users_meta_data.updated_ts = SYSDATE()";

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

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

        return true;

    }
updateUser

@method updateUser($userID, $data_array) Update an existing user record
@access public
@param  int   $userID     Existing userID
@param  array $data_array New user data
@return boolean
@throws InvalidArgumentException Provided argument is now valid userID
@throws Exception

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