get_charset_collate(); $p = $wpdb->prefix . 'frontglut_'; $sql = array(); $sql[] = "CREATE TABLE {$p}forms ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, type varchar(20) NOT NULL DEFAULT 'post', title varchar(200) NOT NULL DEFAULT '', settings longtext, fields longtext, status varchar(20) NOT NULL DEFAULT 'active', created datetime NOT NULL, PRIMARY KEY (id), KEY type (type) ) $c;"; $sql[] = "CREATE TABLE {$p}audit ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, user_id bigint(20) unsigned NOT NULL DEFAULT 0, event varchar(60) NOT NULL, object varchar(120) NOT NULL DEFAULT '', details text, ip varchar(64) NOT NULL DEFAULT '', created datetime NOT NULL, PRIMARY KEY (id), KEY event (event), KEY user_id (user_id) ) $c;"; $sql[] = "CREATE TABLE {$p}notifications ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, user_id bigint(20) unsigned NOT NULL, type varchar(30) NOT NULL DEFAULT 'info', title varchar(200) NOT NULL DEFAULT '', message text, url varchar(255) NOT NULL DEFAULT '', is_read tinyint(1) NOT NULL DEFAULT 0, created datetime NOT NULL, PRIMARY KEY (id), KEY user_read (user_id,is_read) ) $c;"; $sql[] = "CREATE TABLE {$p}messages ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, thread_id bigint(20) unsigned NOT NULL DEFAULT 0, from_id bigint(20) unsigned NOT NULL, to_id bigint(20) unsigned NOT NULL, subject varchar(200) NOT NULL DEFAULT '', body longtext, attachments text, is_read tinyint(1) NOT NULL DEFAULT 0, created datetime NOT NULL, PRIMARY KEY (id), KEY thread (thread_id), KEY to_read (to_id,is_read) ) $c;"; $sql[] = "CREATE TABLE {$p}tickets ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, type varchar(20) NOT NULL DEFAULT 'ticket', user_id bigint(20) unsigned NOT NULL DEFAULT 0, name varchar(120) NOT NULL DEFAULT '', email varchar(120) NOT NULL DEFAULT '', assignee bigint(20) unsigned NOT NULL DEFAULT 0, product_id bigint(20) unsigned NOT NULL DEFAULT 0, subject varchar(200) NOT NULL DEFAULT '', status varchar(20) NOT NULL DEFAULT 'open', priority varchar(20) NOT NULL DEFAULT 'normal', created datetime NOT NULL, updated datetime NOT NULL, PRIMARY KEY (id), KEY type_status (type,status) ) $c;"; $sql[] = "CREATE TABLE {$p}ticket_replies ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, ticket_id bigint(20) unsigned NOT NULL, user_id bigint(20) unsigned NOT NULL DEFAULT 0, body longtext, created datetime NOT NULL, PRIMARY KEY (id), KEY ticket_id (ticket_id) ) $c;"; $sql[] = "CREATE TABLE {$p}commissions ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, order_id bigint(20) unsigned NOT NULL, vendor_id bigint(20) unsigned NOT NULL, gross decimal(19,4) NOT NULL DEFAULT 0, commission decimal(19,4) NOT NULL DEFAULT 0, net decimal(19,4) NOT NULL DEFAULT 0, status varchar(20) NOT NULL DEFAULT 'pending', created datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY order_vendor (order_id,vendor_id), KEY vendor_status (vendor_id,status) ) $c;"; $sql[] = "CREATE TABLE {$p}withdrawals ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, vendor_id bigint(20) unsigned NOT NULL, amount decimal(19,4) NOT NULL, method varchar(40) NOT NULL DEFAULT '', details text, status varchar(20) NOT NULL DEFAULT 'pending', note text, created datetime NOT NULL, processed datetime DEFAULT NULL, PRIMARY KEY (id), KEY vendor_status (vendor_id,status) ) $c;"; $sql[] = "CREATE TABLE {$p}follows ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, user_id bigint(20) unsigned NOT NULL, target_id bigint(20) unsigned NOT NULL, type varchar(20) NOT NULL DEFAULT 'user', created datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY uniq (user_id,target_id,type) ) $c;"; foreach ( apply_filters( 'frontglut_schema', $sql ) as $q ) { dbDelta( $q ); } } private static function create_pages() { $pages = array( 'dashboard_page' => array( __( 'Dashboard', 'frontglut' ), '[frontglut_dashboard]' ), 'login_page' => array( __( 'Login', 'frontglut' ), '[frontglut_login]' ), 'register_page' => array( __( 'Register', 'frontglut' ), '[frontglut_register]' ), 'lost_page' => array( __( 'Lost Password', 'frontglut' ), '[frontglut_lost_password]' ), 'account_page' => array( __( 'My Account', 'frontglut' ), '[frontglut_profile]' ), ); foreach ( $pages as $key => $def ) { $id = (int) Settings::get( 'general.' . $key, 0 ); if ( $id && get_post_status( $id ) ) { continue; } $new = wp_insert_post( array( 'post_title' => $def[0], 'post_content' => $def[1], 'post_status' => 'publish', 'post_type' => 'page', ) ); if ( $new && ! is_wp_error( $new ) ) { Settings::set( 'general.' . $key, (int) $new ); } } } }