wpdb = $wpdb; $this->initialData = array( 'image_url' => get_template_directory_uri().'/img/logo.png', 'favicon' => get_template_directory_uri().'/img/favicon.png', 'fullwidth_layout' => '1', 'show_sitename' => '1', 'show_slider' => '1', 'under_slider_widget' => '1', 'right_sidebar_frontpage' => '1', 'right_sidebar_single' => '1', 'footer_logos' => '1', 'show_tooltips' => '1', 'show_author' => '1', 'show_categories' => '1', 'show_tags' => '1', 'show_megamenu' => '0', 'right_widgets_count' => '3', 'footer_widgets_count' => '3', 'socials' => '1', 'social_positions' => 'facebook:1,twitter:2,instagram:3,google_plus:4,youtube:5,pinterest:6,', 'facebook_social_link' => '#', 'twitter_social_link' => '#', 'instagram_social_link' => '#', 'googleplus_social_link' => '#', 'google_plus_social_link' => '#', 'pinterest_social_link' => '#', 'enable_custom_colors' => '0', ); } 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->initialData as $key => $val) { $toSave = array( 'klucz' => $key, 'wartosc' => $val, ); $maps = array('%s', '%s'); $this->wpdb->insert($table_name, $toSave, $maps); } } function saveEntry(theme_settings_entry $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)); } } ?>