Habari\User::insert PHP Method

insert() public method

Save a new user to the users table
public insert ( )
    public function insert()
    {
        $allow = true;
        $allow = Plugins::filter('user_insert_allow', $allow, $this);
        if (!$allow) {
            return;
        }
        Plugins::act('user_insert_before', $this);
        $this->exclude_fields('id');
        $result = parent::insertRecord(DB::table('users'));
        $this->fields['id'] = DB::last_insert_id();
        // Make sure the id is set in the user object to match the row id
        $this->info->set_key($this->id);
        /* If a new user is being created and inserted into the db, info is only safe to use _after_ this set_key call. */
        // $this->info->option_default = "saved";
        // Set the default timezone, date format, and time format
        $this->info->locale_tz = Options::get('timezone');
        $this->info->locale_date_format = Options::get('dateformat');
        $this->info->locale_time_format = Options::get('timeformat');
        $this->info->locale_lang = Options::get('locale', 'en-us');
        // Save when this user was created
        $this->info->creation_time = DateTime::create()->format('Y-m-d H:i:s');
        $this->info->commit();
        if ($result) {
            // Add the user to the default authenticated group if it exists
            if (UserGroup::exists('authenticated')) {
                $this->add_to_group('authenticated');
            }
        }
        EventLog::log(_t('New user created: %s', array($this->username)), 'info', 'default', 'habari');
        Plugins::act('user_insert_after', $this);
        return $result;
    }