get_all_fields(null, true); // Get enabled fields only foreach ($fields as $field) { $field_key = $field['field_key']; $field_type = $field['field_type']; // phpcs:ignore WordPress.Security.NonceVerification.Missing $field_value = isset($_POST[$field_key]) ? sanitize_text_field(wp_unslash($_POST[$field_key])) : ''; // Skip if field is empty and not required if (empty($field_value) && !$field['required']) { continue; } // Validate based on field type switch ($field_type) { case 'email': $this->validate_email($field_key, $field_value, $field['label'], $errors); break; case 'tel': $this->validate_phone($field_key, $field_value, $field['label'], $errors); break; // URL validation REMOVED - field renders as text, no validation needed // Save for PRO version } } } /** * Validate email field */ private function validate_email($field_key, $value, $label, $errors) { if (empty($value)) { return; // Already handled by required validation } if (!is_email($value)) { $errors->add( 'validation', sprintf( /* translators: %s: field label */ __('%s is not a valid email address.', 'akz-checkout-fields-manager-for-woocommerce'), $label ) ); } } /** * Validate phone field */ private function validate_phone($field_key, $value, $label, $errors) { if (empty($value)) { return; // Already handled by required validation } // Basic phone validation (digits, spaces, hyphens, parentheses, plus sign) $phone_pattern = '/^[\d\s\-\(\)\+]+$/'; if (!preg_match($phone_pattern, $value)) { $errors->add( 'validation', sprintf( /* translators: %s: field label */ __('%s is not a valid phone number.', 'akz-checkout-fields-manager-for-woocommerce'), $label ) ); return; } // Check minimum length (at least 7 digits) $digits_only = preg_replace('/[^\d]/', '', $value); if (strlen($digits_only) < 7) { $errors->add( 'validation', sprintf( /* translators: %s: field label */ __('%s must contain at least 7 digits.', 'akz-checkout-fields-manager-for-woocommerce'), $label ) ); } } /** * Validate URL field * DISABLED IN FREE VERSION - Save for PRO */ /* private function validate_url($field_key, $value, $label, $errors) { if (empty($value)) { return; // Already handled by required validation } if (!filter_var($value, FILTER_VALIDATE_URL)) { $errors->add( 'validation', sprintf( __('%s is not a valid URL.', 'akz-checkout-fields-manager-for-woocommerce'), $label ) ); } } */ }