function delete() { global $wpdb; if ($this->initial) { return; } $table_name = wpcf7_table_name(); $query = $wpdb->prepare("DELETE FROM {$table_name} WHERE cf7_unit_id = %d LIMIT 1", absint($this->id)); $wpdb->query($query); $this->initial = true; $this->id = null; }
function wpcf7_contact_forms() { global $wpdb; $table_name = wpcf7_table_name(); return $wpdb->get_results("SELECT cf7_unit_id as id, title FROM {$table_name}"); }
function wpcf7_install() { global $wpdb; if (wpcf7_table_exists()) { return; } // Exists already $table_name = wpcf7_table_name(); $charset_collate = ''; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } $wpdb->query("CREATE TABLE IF NOT EXISTS {$table_name} (\n\t\tcf7_unit_id bigint(20) unsigned NOT NULL auto_increment,\n\t\ttitle varchar(200) NOT NULL default '',\n\t\tform text NOT NULL,\n\t\tmail text NOT NULL,\n\t\tmail_2 text NOT NULL,\n\t\tmessages text NOT NULL,\n\t\tadditional_settings text NOT NULL,\n\t\tPRIMARY KEY (cf7_unit_id)) {$charset_collate};"); if (!wpcf7_table_exists()) { return false; } // Failed to create $legacy_data = get_option('wpcf7'); if (is_array($legacy_data)) { foreach ($legacy_data['contact_forms'] as $key => $value) { $wpdb->insert($table_name, array('cf7_unit_id' => $key, 'title' => $value['title'], 'form' => maybe_serialize($value['form']), 'mail' => maybe_serialize($value['mail']), 'mail_2' => maybe_serialize($value['mail_2']), 'messages' => maybe_serialize($value['messages']), 'additional_settings' => maybe_serialize($value['additional_settings'])), array('%d', '%s', '%s', '%s', '%s', '%s', '%s')); } // delete_option( 'wpcf7' ); // Comment out for downgrading case for a while } else { wpcf7_load_plugin_textdomain(); $wpdb->insert($table_name, array('title' => __('Contact form', 'wpcf7') . ' 1', 'form' => maybe_serialize(wpcf7_default_form_template()), 'mail' => maybe_serialize(wpcf7_default_mail_template()), 'mail_2' => maybe_serialize(wpcf7_default_mail_2_template()), 'messages' => maybe_serialize(wpcf7_default_messages_template()))); } }