prefix . 'accordion_faq_events'; } /** * Full search-terms table name. * * @return string */ public static function searches_table() { global $wpdb; return $wpdb->prefix . 'accordion_faq_searches'; } /** * Create/upgrade the analytics tables. * * @return void */ public static function create_table() { global $wpdb; $table = self::table(); $searches = self::searches_table(); $charset = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$table} ( faq_id BIGINT(20) UNSIGNED NOT NULL, event_type VARCHAR(10) NOT NULL, event_day DATE NOT NULL, hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (faq_id, event_type, event_day), KEY event_day (event_day), KEY event_type (event_type) ) {$charset};"; $sql .= "\nCREATE TABLE {$searches} ( term VARCHAR(120) NOT NULL, event_day DATE NOT NULL, hits BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, results INT(10) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (term, event_day), KEY event_day (event_day) ) {$charset};"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); } /** * Drop the tables (used on data removal). * * @return void */ public static function drop_table() { global $wpdb; foreach ( array( self::table(), self::searches_table() ) as $table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.SchemaChange -- dropping the plugin's own custom table on uninstall has no WordPress API alternative. $wpdb->query( $wpdb->prepare( 'DROP TABLE IF EXISTS %i', $table ) ); } // The analytics data no longer exists; drop any cached aggregates too. wp_cache_delete( 'last_changed', self::CACHE_GROUP ); } }