get_charset_collate(); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $table_forms = $wpdb->prefix . 'wpvfb_forms'; $sql_forms = "CREATE TABLE $table_forms ( id varchar(36) NOT NULL, name varchar(255) NOT NULL, fields longtext NULL, settings longtext NULL, confirmations longtext NULL, notifications longtext NULL, is_active tinyint(1) DEFAULT 1 NOT NULL, created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; dbDelta( $sql_forms ); $table_entries = $wpdb->prefix . 'wpvfb_entries'; $sql_entries = "CREATE TABLE $table_entries ( id varchar(36) NOT NULL, form_id varchar(36) NOT NULL, data longtext NOT NULL, user_ip varchar(45) NULL, user_agent text NULL, created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY (id), KEY form_id (form_id) ) $charset_collate;"; dbDelta( $sql_entries ); update_option( 'wpvfb_db_version', self::DB_VERSION ); } /** * Activation hooks do not run on plugin updates, so new columns are added here. * dbDelta only adds missing columns; existing data is never dropped. */ public static function maybe_upgrade() { if ( get_option( 'wpvfb_db_version' ) !== self::DB_VERSION ) { self::activate(); } } }