*/ public static function tables() { global $wpdb; return array( 'forms' => $wpdb->prefix . 'fillaro_forms', 'entries' => $wpdb->prefix . 'fillaro_entries', 'values' => $wpdb->prefix . 'fillaro_entry_values', 'stats' => $wpdb->prefix . 'fillaro_form_stats', ); } /** * Create or update tables with dbDelta. */ private static function create_tables() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $t = self::tables(); $charset = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$t['forms']} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, title varchar(255) NOT NULL DEFAULT '', status varchar(20) NOT NULL DEFAULT 'published', fields longtext NOT NULL, settings longtext NOT NULL, theme longtext NOT NULL, created_by bigint(20) unsigned NOT NULL DEFAULT 0, created_at datetime NOT NULL, updated_at datetime NOT NULL, PRIMARY KEY (id), KEY status (status) ) $charset; CREATE TABLE {$t['entries']} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, form_id bigint(20) unsigned NOT NULL, status varchar(20) NOT NULL DEFAULT 'unread', is_starred tinyint(1) NOT NULL DEFAULT 0, user_id bigint(20) unsigned NOT NULL DEFAULT 0, ip_hash varchar(64) NOT NULL DEFAULT '', source_url text NULL, user_agent varchar(255) NOT NULL DEFAULT '', created_at datetime NOT NULL, PRIMARY KEY (id), KEY form_created (form_id,created_at), KEY form_status (form_id,status) ) $charset; CREATE TABLE {$t['values']} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, entry_id bigint(20) unsigned NOT NULL, form_id bigint(20) unsigned NOT NULL, field_key varchar(100) NOT NULL, value longtext NULL, PRIMARY KEY (id), KEY entry_id (entry_id), KEY form_field (form_id,field_key) ) $charset; CREATE TABLE {$t['stats']} ( form_id bigint(20) unsigned NOT NULL, day date NOT NULL, views int(10) unsigned NOT NULL DEFAULT 0, starts int(10) unsigned NOT NULL DEFAULT 0, submissions int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (form_id,day) ) $charset;"; dbDelta( $sql ); } }