function messages_install() { global $wpdb, $bp; if ( !empty($wpdb->charset) ) $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; $sql[] = "CREATE TABLE {$bp->messages->table_name_recipients} ( id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, user_id bigint(20) NOT NULL, thread_id bigint(20) NOT NULL, unread_count int(10) NOT NULL DEFAULT '0', sender_only tinyint(1) NOT NULL DEFAULT '0', is_deleted tinyint(1) NOT NULL DEFAULT '0', KEY user_id (user_id), KEY thread_id (thread_id), KEY is_deleted (is_deleted), KEY sender_only (sender_only), KEY unread_count (unread_count) ) {$charset_collate};"; $sql[] = "CREATE TABLE {$bp->messages->table_name_messages} ( id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, thread_id bigint(20) NOT NULL, sender_id bigint(20) NOT NULL, subject varchar(200) NOT NULL, message longtext NOT NULL, date_sent datetime NOT NULL, KEY sender_id (sender_id), KEY thread_id (thread_id) ) {$charset_collate};"; $sql[] = "CREATE TABLE {$bp->messages->table_name_notices} ( id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, subject varchar(200) NOT NULL, message longtext NOT NULL, date_sent datetime NOT NULL, is_active tinyint(1) NOT NULL DEFAULT '0', KEY is_active (is_active) ) {$charset_collate};"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta($sql); /* Upgrade and remove the message threads table if it exists */ if ( $wpdb->get_var( "SHOW TABLES LIKE '%{$wpdb->base_prefix}bp_messages_threads%'" ) ) { $upgrade = BP_Messages_Thread::upgrade_tables(); if ( $upgrade ) $wpdb->query( "DROP TABLE {$wpdb->base_prefix}bp_messages_threads" ); } add_site_option( 'bp-messages-db-version', BP_MESSAGES_DB_VERSION ); }