prefix . self::TABLE; } /** Legt die Tabelle an oder aktualisiert sie (dbDelta ist wiederholbar). */ public static function install() { global $wpdb; $table = self::table_name(); $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$table} ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, created_at DATETIME NOT NULL, subject VARCHAR(255) NOT NULL DEFAULT '', recipients TEXT NOT NULL, sender VARCHAR(255) NOT NULL DEFAULT '', headers TEXT NOT NULL, body LONGTEXT NOT NULL, is_html TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, attachments TEXT NOT NULL, PRIMARY KEY (id), KEY created_at (created_at) ) {$charset_collate};"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); update_option( self::VERSION_OPTION, self::DB_VERSION, false ); } /** * Legt die Tabelle an, wenn sie fehlt oder veraltet ist. Haengt an * admin_init: Bei netzwerkweiter Aktivierung entsteht die Tabelle einer * Site so beim ersten Backend-Aufruf, ohne dass die Aktivierung alle * Sites durchlaufen muss. */ public static function maybe_upgrade() { if ( get_option( self::VERSION_OPTION ) !== self::DB_VERSION ) { self::install(); } } /** Entfernt Tabelle und Versionsmerker (nur beim Loeschen des Plugins). */ public static function uninstall() { global $wpdb; $table = self::table_name(); $wpdb->query( "DROP TABLE IF EXISTS `{$table}`" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter -- eigene Tabelle, Name aus Praefix und fester Konstante. delete_option( self::VERSION_OPTION ); } }