array( 'label' => __('Text', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📝', 'category' => 'basic', 'description' => __('Single line text input', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('placeholder', 'default', 'validation'), ), 'textarea' => array( 'label' => __('Textarea', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📄', 'category' => 'basic', 'description' => __('Multi-line text input', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('placeholder', 'default', 'rows'), ), 'number' => array( 'label' => __('Number', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '🔢', 'category' => 'basic', 'description' => __('Numeric input with min/max', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('placeholder', 'default', 'min', 'max', 'step'), ), 'altemail' => array( 'label' => __('Alternate Email', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📧', 'category' => 'basic', 'description' => __('Email address with validation', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('placeholder', 'default', 'validation'), ), 'altphone' => array( 'label' => __('Alternate Phone', 'akz-checkout-fields-manager-for-woocommerce'), 'type' => 'tel', // HTML5 type 'icon' => '📞', 'category' => 'basic', 'description' => __('Phone number input', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('placeholder', 'default', 'validation'), ), 'url' => array( 'label' => __('URL', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '🔗', 'category' => 'basic', 'description' => __('Website URL with validation', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('placeholder', 'default', 'validation'), ), 'password' => array( 'label' => __('Password', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '🔒', 'category' => 'basic', 'description' => __('Password input (hidden)', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('placeholder'), ), 'hidden' => array( 'label' => __('Hidden', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '👻', 'category' => 'basic', 'description' => __('Hidden field (not visible)', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('default'), ), // Selection Fields 'select' => array( 'label' => __('Select', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📋', 'category' => 'selection', 'description' => __('Dropdown selection', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('options', 'default'), ), 'multiselect' => array( 'label' => __('Multi Select', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '☑️', 'category' => 'selection', 'description' => __('Multiple selection dropdown', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('options', 'default'), ), 'radio' => array( 'label' => __('Radio', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '🔘', 'category' => 'selection', 'description' => __('Radio button group', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('options', 'default'), ), 'checkbox' => array( 'label' => __('Checkbox', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '✅', 'category' => 'selection', 'description' => __('Single checkbox', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('default', 'text'), ), 'checkboxgroup' => array( 'label' => __('Checkbox Group', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '☑️', 'category' => 'selection', 'description' => __('Multiple checkboxes', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('options', 'default'), ), // Date & Time Fields 'date' => array( 'label' => __('Date', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📅', 'category' => 'datetime', 'description' => __('Date picker (YYYY-MM-DD)', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('default', 'min', 'max'), ), 'datetime-local' => array( 'label' => __('DateTime Local', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '🕐', 'category' => 'datetime', 'description' => __('Date and time picker', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('default', 'min', 'max'), ), 'time' => array( 'label' => __('Time', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '⏰', 'category' => 'datetime', 'description' => __('Time picker (HH:MM)', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('default', 'min', 'max'), ), 'month' => array( 'label' => __('Month', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📆', 'category' => 'datetime', 'description' => __('Month and year picker', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('default', 'min', 'max'), ), 'week' => array( 'label' => __('Week', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📊', 'category' => 'datetime', 'description' => __('Week picker', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('default', 'min', 'max'), ), // Display Only Fields 'heading' => array( 'label' => __('Heading', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📌', 'category' => 'display', 'description' => __('Section heading (no input)', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('text', 'class'), ), 'paragraph' => array( 'label' => __('Paragraph', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📄', 'category' => 'display', 'description' => __('Text paragraph (no input)', 'akz-checkout-fields-manager-for-woocommerce'), 'supports' => array('text', 'class'), ), ); } /** * Get field type categories * * @return array Categories with labels */ public static function get_categories() { return array( 'basic' => array( 'label' => __('Basic Fields', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📝', ), 'selection' => array( 'label' => __('Selection Fields', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '☑️', ), 'datetime' => array( 'label' => __('Date & Time', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📅', ), 'display' => array( 'label' => __('Display Only', 'akz-checkout-fields-manager-for-woocommerce'), 'icon' => '📌', ), ); } /** * Get field type by key * * @param string $type Field type key * @return array|null Field type data or null */ public static function get_field_type($type) { $types = self::get_field_types(); return isset($types[$type]) ? $types[$type] : null; } /** * Check if field type exists * * @param string $type Field type key * @return bool */ public static function field_type_exists($type) { $types = self::get_field_types(); return isset($types[$type]); } /** * Get field types by category * * @param string $category Category key * @return array Field types in category */ public static function get_field_types_by_category($category) { $types = self::get_field_types(); $filtered = array(); foreach ($types as $key => $type) { if (isset($type['category']) && $type['category'] === $category) { $filtered[$key] = $type; } } return $filtered; } /** * Validate field type * * @param string $type Field type to validate * @return string Valid field type or 'text' as fallback */ public static function validate_field_type($type) { return self::field_type_exists($type) ? $type : 'text'; } /** * Sanitize field data before saving * * @param array $data Raw field data * @return array Sanitized field data */ public static function sanitize_field_data($data) { // Check if this is an existing field (for backward compatibility) $is_existing = !empty($data['id']) || (!empty($data['field_key']) && self::field_exists($data['field_key'])); // Use CFEP_Security for comprehensive sanitization $sanitized = CFEP_Security::sanitize_field_data($data, $is_existing); // Validate field type against our whitelist $sanitized['field_type'] = self::validate_field_type($sanitized['field_type']); return $sanitized; } /** * Check if field exists (for backward compatibility check) */ private static function field_exists($field_key) { global $wpdb; $table = $wpdb->prefix . 'cfep_fields'; $cache_key = 'cfep_field_exists_' . $field_key; $exists = wp_cache_get($cache_key, 'cfep'); if ($exists === false) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $exists = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE field_key = %s", $field_key ) ); wp_cache_set($cache_key, $exists, 'cfep', 300); } return $exists > 0; } }