get_charset_collate(); $sql = "CREATE TABLE $table_name ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, timestamp datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, user_id bigint(20) unsigned DEFAULT NULL, user_email varchar(100) DEFAULT NULL, ip_address varchar(45) DEFAULT NULL, event_type varchar(50) NOT NULL, object_type varchar(50) DEFAULT NULL, object_id bigint(20) unsigned DEFAULT NULL, summary text, details longtext, import_source varchar(20) DEFAULT NULL, import_id bigint(20) unsigned DEFAULT NULL, country char(2) DEFAULT NULL, city varchar(80) DEFAULT NULL, device_class varchar(10) DEFAULT NULL, browser varchar(40) DEFAULT NULL, os varchar(40) DEFAULT NULL, chain_prev char(64) DEFAULT NULL, chain_content char(64) DEFAULT NULL, chain_hash char(64) DEFAULT NULL, chain_redacted tinyint(1) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (id), KEY timestamp (timestamp), KEY user_id (user_id), KEY event_type (event_type), KEY object_type (object_type), UNIQUE KEY import_ref (import_source,import_id,timestamp), UNIQUE KEY chain_prev (chain_prev) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); } /** * Drop the activity log table. */ public static function drop_table(): void { global $wpdb; $table_name = self::get_table_name(); // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "DROP TABLE IF EXISTS $table_name;" ); // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared delete_option( self::SCHEMA_OPTION ); } /** * Get the full table name with prefix. */ public static function get_table_name(): string { global $wpdb; return $wpdb->prefix . self::TABLE_NAME; } }