prefix . 'cfep_block_fields'; $charset_collate = $wpdb->get_charset_collate(); // Check if table already exists // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { return true; } $sql = "CREATE TABLE $table_name ( id bigint(20) NOT NULL AUTO_INCREMENT, field_key varchar(200) NOT NULL, field_type varchar(50) NOT NULL DEFAULT 'text', location varchar(50) NOT NULL DEFAULT 'contact', label varchar(255) NOT NULL, placeholder varchar(255) DEFAULT NULL, description text DEFAULT NULL, required tinyint(1) NOT NULL DEFAULT 0, enabled tinyint(1) NOT NULL DEFAULT 1, position int(11) NOT NULL DEFAULT 0, field_class varchar(255) DEFAULT NULL, options longtext DEFAULT NULL, conditional_logic longtext DEFAULT NULL, validation_rules longtext DEFAULT NULL, is_default tinyint(1) NOT NULL DEFAULT 0, can_delete tinyint(1) NOT NULL DEFAULT 1, created_at datetime DEFAULT CURRENT_TIMESTAMP, updated_at datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY field_key (field_key), KEY location (location), KEY enabled (enabled), KEY position (position) ) $charset_collate;"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); // Verify table was created // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") == $table_name) { // Copy existing fields to Block table (optional - for migration) self::copy_classic_to_block(); return true; } return false; } /** * Copy Classic Checkout fields to Block Checkout * This helps users migrate smoothly */ private static function copy_classic_to_block() { global $wpdb; $classic_table = $wpdb->prefix . 'cfep_fields'; $block_table = $wpdb->prefix . 'cfep_block_fields'; // DON'T copy - we'll load WooCommerce defaults separately // Just mark as ready for WC fields loader update_option('cfep_block_needs_wc_fields', 1); } /** * Map Classic section to Block location */ private static function map_section_to_location($section) { $mapping = array( 'billing' => 'contact', 'shipping' => 'address', 'order' => 'contact' ); return $mapping[$section] ?? 'contact'; } }