wpdb = $wpdb; $this->initial_data = array( 'social_positions' => 'facebook:1,twitter:2,instagram:3,google_plus:4,youtube:5,pinterest:6,', 'facebook_social_link' => '#', 'twitter_social_link' => '#', 'instagram_social_link' => '#', 'youtube_social_link' => '#', 'google_plus_social_link' => '#', 'pinterest_social_link' => '#', ); } function getTableName(){ return $this->wpdb->prefix.$this->table_name; } function createTable(){ $table_name = $this->getTableName(); $sql = ' CREATE TABLE IF NOT EXISTS '. $table_name .' ( klucz VARCHAR(255) NOT NULL, wartosc VARCHAR(255) NOT NULL, PRIMARY KEY(klucz) )ENGINE=InnoDB DEFAULT CHARSET=utf8'; require_once ABSPATH.'wp-admin/includes/upgrade.php'; dbDelta($sql); $this->initDbData(); } function initDbData(){ $table_name = $this->getTableName(); foreach($this->initial_data as $key => $val){ $toSave = array( 'klucz' => $key, 'wartosc' => $val, ); $maps = array('%s', '%s'); $this->wpdb->replace($table_name, $toSave, $maps); } } function saveEntry(AmadeoThemeSettingsEntry $entry){ $table_name = $this->getTableName(); foreach($entry as $key => $val){ $toSave = array( 'klucz' => $key, 'wartosc' => $val, ); $maps = array('%s', '%s'); $this->wpdb->replace($table_name, $toSave, $maps); } } function getDbField($key){ $table_name = $this->getTableName(); return $this->wpdb->get_var($this->wpdb->prepare('SELECT wartosc FROM '. $table_name .' WHERE klucz = %s', $key)); } function getSocialsDbKeys($key){ $table_name = $this->getTableName(); return $this->wpdb->get_results($this->wpdb->prepare('SELECT klucz FROM '. $table_name .' WHERE klucz LIKE %s AND wartosc <> ""', $key)); } } ?>