# charitable/1.8.13/includes/data/class-charitable-donormeta-db.php

Charitable – Donation &amp; Fundraising Platform (Donation Forms, Recurring Donations &amp; Fundraising Campaigns), version 1.8.13. 130 lines.

- Page: https://pluginprobe.com/plugins/charitable/1.8.13/code/includes/data/class-charitable-donormeta-db.php
- Raw: https://pluginprobe.com/plugins/charitable/1.8.13/raw/includes/data/class-charitable-donormeta-db.php
- Modified: 2023-11-01T16:41:02+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/charitable/1.8.13/code/includes/data/class-charitable-donormeta-db.php#L10-L20`.

```php
<?php
/**
 * Charitable Donormeta DB class.
 *
 * @package   Charitable/Classes/Charitable_Donormeta_DB
 * @author    David Bisset
 * @copyright Copyright (c) 2023, WP Charitable LLC
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since     1.6.0
 * @version   1.6.0
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Charitable_Donormeta_DB' ) ) :

	/**
	 * Charitable_Donormeta_DB
	 *
	 * @since 1.6.0
	 */
	class Charitable_Donormeta_DB extends Charitable_DB {

		/**
		 * The version of our database table
		 *
		 * @since 1.6.0
		 *
		 * @var   string
		 */
		public $version = '1.6.0';

		/**
		 * The name of the primary column
		 *
		 * @since 1.6.0
		 *
		 * @var   string
		 */
		public $primary_key = 'meta_id';

		/**
		 * Set up the database table name.
		 *
		 * @since 1.6.0
		 *
		 * @global WPDB $wpdb
		 */
		public function __construct() {
			global $wpdb;

			$this->table_name = $wpdb->prefix . 'charitable_donormeta';
		}

		/**
		 * Create the table.
		 *
		 * @since 1.6.0
		 *
		 * @global WPDB $wpdb
		 */
		public function create_table() {
			global $wpdb;

			$charset_collate = $wpdb->get_charset_collate();

			$sql = "CREATE TABLE {$this->table_name} (
                meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
                donor_id bigint(20) unsigned NOT NULL DEFAULT '0',
                meta_key varchar(255) DEFAULT NULL,
                meta_value longtext,
				PRIMARY KEY  (meta_id),
				KEY donor_id (donor_id),
				KEY meta_key (meta_key(191))
				) $charset_collate;";

			$this->_create_table( $sql );
		}

		/**
		 * Whitelist of columns.
		 *
		 * @since  1.6.0
		 *
		 * @return array
		 */
		public function get_columns() {
			return array(
				'meta_id'    => '%d',
				'donor_id'   => '%d',
				'meta_key'   => '%s',
				'meta_value' => '%s',
			);
		}

		/**
		 * Default column values.
		 *
		 * @since  1.6.0
		 *
		 * @return array
		 */
		public function get_column_defaults() {
			return array(
				'meta_id'    => '',
				'donor_id'   => 0,
				'meta_key'   => '',
				'meta_value' => '',
			);
		}

		/**
		 * Add a new donor meta item.
		 *
		 * @since  1.6.0
		 *
		 * @param  array  $data Donor data to insert.
		 * @param  string $type Should always be 'donormeta'.
		 * @return int The ID of the inserted donor.
		 */
		public function insert( $data, $type = 'donormeta' ) {
			return parent::insert( $data, $type );
		}
	}

endif;

```
