WordPress\ORM\BaseModel::save PHP Méthode

save() public méthode

Save this model to the database. Will create a new record if the ID property isn't set, or update an existing record if the ID property is set.
public save ( ) : integer
Résultat integer
    public function save()
    {
        global $wpdb;
        // Get the model's properties
        $props = $this->properties();
        // Flatten complex objects
        $props = $this->flatten_props($props);
        // Insert or update?
        if (is_null($props[static::get_primary_key()])) {
            $wpdb->insert($this->get_table(), $props);
            $this->{static::get_primary_key()} = $wpdb->insert_id;
        } else {
            $wpdb->update(static::get_table(), $props, array(static::get_primary_key() => $this->{static::get_primary_key()}));
        }
        return $this->id;
    }