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;
    }
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;
    }
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 ; }
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.

@return integer
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 .