public function insert( $data ) {

		// Set default values
		$data = wp_parse_args( $data, $this->table->get_column_defaults() );

		$columns = $this->table->get_columns();

		// White list columns
		$data = array_intersect_key( $data, $columns );

		$null_columns = array();

		foreach ( $data as $col => $val ) {

			if ( $val === null ) {
				$null_columns[] = $col;
			}
		}

		foreach ( $null_columns as $null_column ) {
			unset( $data[ $null_column ] );
		}

		foreach ( $data as $name => $value ) {
			$data[ $name ] = $this->prepare_for_storage( $name, $value );
		}

		$formats = array_fill( 0, count( $data ), '%s' );

		$prev = $this->wpdb->show_errors( false );
		$this->wpdb->insert( $this->table->get_table_name( $this->wpdb ), $data, $formats );
		$this->wpdb->show_errors( $prev );

		if ( $this->wpdb->last_error ) {
			throw $this->generate_exception_from_db_error();
		}

		return $this->wpdb->insert_id;
	}
public function insert( $data ) {

		// Set default values
		$data = wp_parse_args( $data, $this->table->get_column_defaults() );

		$columns = $this->table->get_columns();

		// White list columns
		$data = array_intersect_key( $data, $columns );

		$null_columns = array();

		foreach ( $data as $col => $val ) {

			if ( $val === null ) {
				$null_columns[] = $col;
			}
		}

		foreach ( $null_columns as $null_column ) {
			unset( $data[ $null_column ] );
		}

		foreach ( $data as $name => $value ) {
			$data[ $name ] = $this->prepare_for_storage( $name, $value );
		}

		$formats = array_fill( 0, count( $data ), '%s' );

		$prev = $this->wpdb->show_errors( false );
		$this->wpdb->insert( $this->table->get_table_name( $this->wpdb ), $data, $formats );
		$this->wpdb->show_errors( $prev );

		if ( $this->wpdb->last_error ) {
			throw $this->generate_exception_from_db_error();
		}

		return $this->wpdb->insert_id;
	}
public function insert ( $ data ) { // Set default values $ data = wp_parse_args ( $ data , $ this -> table -> get_column_defaults ( ) ) ; $ columns = $ this -> table -> get_columns ( ) ; // White list columns $ data = array_intersect_key ( $ data , $ columns ) ; $ null_columns = array ( ) ; foreach ( $ data as $ col => $ val ) { if ( $ val === null ) { $ null_columns [ ] = $ col ; } } foreach ( $ null_columns as $ null_column ) { unset ( $ data [ $ null_column ] ) ; } foreach ( $ data as $ name => $ value ) { $ data [ $ name ] = $ this -> prepare_for_storage ( $ name , $ value ) ; } $ formats = array_fill ( 0 , count ( $ data ) , '%s' ) ; $ prev = $ this -> wpdb -> show_errors ( false ) ; $ this -> wpdb -> insert ( $ this -> table -> get_table_name ( $ this -> wpdb ) , $ data , $ formats ) ; $ this -> wpdb -> show_errors ( $ prev ) ; if ( $ this -> wpdb -> last_error ) { throw $ this -> generate_exception_from_db_error ( ) ; } return $ this -> wpdb -> insert_id ; }
Insert a new row

@since 1.0

@param array $data

@return mixed Insert ID

@throws Exception
Insert a new row