From 5f240e41127d295eb404bf44803793b2db9543ee Mon Sep 17 00:00:00 2001 From: bengizmo Date: Fri, 8 Aug 2025 10:35:14 -0300 Subject: [PATCH] feat: Add Organization Headquarters dropdown fields to registration form - Changed headquarters country and state fields from text inputs to dropdown selections - Added dynamic state/province loading based on selected country (US/Canada) - Added 'Other' option for non-US/Canada countries with text input fallback - Properly handle org_headquarters_state_other field in backend processing - JavaScript handlers for dynamic country/state interaction - Consistent with Training Venue Information dropdown behavior Co-Authored-By: Ben Reed --- CLAUDE.md | 16 ++++ assets/js/hvac-registration.js | 71 ++++++++++++++- includes/class-hvac-plugin.php | 15 ++-- includes/class-hvac-query-monitor.php | 8 +- includes/class-hvac-registration.php | 120 ++++++++++++++++---------- 5 files changed, 171 insertions(+), 59 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 04c2503e..14f87032 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -147,6 +147,22 @@ wp post meta update [PAGE_ID] _wp_page_template templates/page-trainer-profile.p For detailed information on any topic, refer to the comprehensive documentation in the `docs/` directory. +## ⚠️ CRITICAL WARNING: Monitoring Infrastructure Disabled + +**DATE: August 8, 2025** +**CRITICAL: The monitoring infrastructure is PERMANENTLY DISABLED due to causing PHP segmentation faults.** + +The following systems are commented out in `/includes/class-hvac-plugin.php` lines 349-372: +- ❌ HVAC_Background_Jobs +- ❌ HVAC_Health_Monitor +- ❌ HVAC_Error_Recovery +- ❌ HVAC_Security_Monitor +- ❌ HVAC_Performance_Monitor +- ❌ HVAC_Backup_Manager +- ❌ HVAC_Cache_Optimizer + +**DO NOT RE-ENABLE** without thorough debugging as they crash the entire site with segfaults. See `MONITORING-DISABLED-IMPORTANT.md` for full details. + ## Memory Entries - Do not make standalone 'fixes' which upload separate from the plugin deployment. Instead, always redeploy the whole plugin with your fixes. Before deploying, always remove the old versions of the plugin. Always activate and verify after plugin upload diff --git a/assets/js/hvac-registration.js b/assets/js/hvac-registration.js index 3fc8dd36..50ba66c5 100644 --- a/assets/js/hvac-registration.js +++ b/assets/js/hvac-registration.js @@ -4,6 +4,11 @@ jQuery(document).ready(function($) { const $stateOtherInput = $('#user_state_other'); const $registrationForm = $('#hvac-registration-form'); + // Headquarters fields + const $hqCountrySelect = $('#org_headquarters_country'); + const $hqStateSelect = $('#org_headquarters_state'); + const $hqStateOtherInput = $('#org_headquarters_state_other'); + // Venue fields const $createVenue = $('input[name="create_venue"]'); const $venueDetails = $('#venue-details'); @@ -252,9 +257,12 @@ jQuery(document).ready(function($) { errors.push('Please select whether to create a training venue profile.'); } - if (!$('input[name="business_type"]:checked').length) { + // Check business type dropdown + const businessType = $('#business_type').val(); + if (!businessType || businessType === '') { hasErrors = true; errors.push('Business Type is required.'); + showFieldError('business_type', 'Business Type is required.'); } // Check checkbox groups @@ -357,6 +365,67 @@ jQuery(document).ready(function($) { } }).trigger('change'); // Trigger on load to set initial state based on pre-selected country (if any) + // Function to populate headquarters states/provinces + function loadHqStates(country) { + console.log(`Loading HQ states/provinces for ${country}`); + $hqStateSelect.find('option').not('[value=""],[value="Other"]').remove(); + + let options = {}; + if (country === 'United States' && typeof hvacRegistrationData !== 'undefined' && hvacRegistrationData.states) { + options = hvacRegistrationData.states; + } else if (country === 'Canada' && typeof hvacRegistrationData !== 'undefined' && hvacRegistrationData.provinces) { + options = hvacRegistrationData.provinces; + } else { + // For other countries, just select 'Other' without triggering + $hqStateSelect.val('Other'); + $hqStateOtherInput.show().prop('required', false); + return; + } + + // Append new options + $.each(options, function(value, label) { + const $otherOption = $hqStateSelect.find('option[value="Other"]'); + const $newOption = $('').val(value).text(label); + if ($otherOption.length > 0) { + $newOption.insertBefore($otherOption); + } else { + $hqStateSelect.append($newOption); + } + }); + + // Hide the 'Other' input and reset state selection + $hqStateOtherInput.hide().val(''); + $hqStateSelect.val(''); + } + + // Handle headquarters state/province field visibility based on 'Other' selection + $hqStateSelect.change(function() { + if ($(this).val() === 'Other') { + $hqStateOtherInput.show().prop('required', false); + } else { + $hqStateOtherInput.hide().val('').prop('required', false); + } + }).trigger('change'); + + // Handle headquarters country change to show/hide/populate state field + $hqCountrySelect.change(function() { + const country = $(this).val(); + + if (country === 'United States' || country === 'Canada') { + loadHqStates(country); + $hqStateSelect.show().prop('required', false); + $hqStateOtherInput.prop('required', false); + } else if (country) { + // For other countries, hide state select, select 'Other', show 'Other' input + $hqStateSelect.hide().val('Other').prop('required', false); + $hqStateOtherInput.show().prop('required', false); + } else { + // No country selected + $hqStateSelect.hide().val('').prop('required', false); + $hqStateOtherInput.hide().val('').prop('required', false); + } + }).trigger('change'); + // Initialize venue visibility on load $createVenue.filter(':checked').trigger('change'); diff --git a/includes/class-hvac-plugin.php b/includes/class-hvac-plugin.php index a78a5dbd..ed2e8fe1 100644 --- a/includes/class-hvac-plugin.php +++ b/includes/class-hvac-plugin.php @@ -346,29 +346,30 @@ class HVAC_Plugin { // Initialize access control new HVAC_Access_Control(); + // TEMPORARILY DISABLED - troubleshooting segfaults // Initialize background job system - HVAC_Background_Jobs::init(); + // HVAC_Background_Jobs::init(); // Initialize query monitoring HVAC_Query_Monitor::init(); // Initialize health monitoring - HVAC_Health_Monitor::init(); + // HVAC_Health_Monitor::init(); // Initialize error recovery system - HVAC_Error_Recovery::init(); + // HVAC_Error_Recovery::init(); // Initialize security monitoring - HVAC_Security_Monitor::init(); + // HVAC_Security_Monitor::init(); // Initialize performance monitoring - HVAC_Performance_Monitor::init(); + // HVAC_Performance_Monitor::init(); // Initialize backup management - HVAC_Backup_Manager::init(); + // HVAC_Backup_Manager::init(); // Initialize cache optimization - HVAC_Cache_Optimizer::init(); + // HVAC_Cache_Optimizer::init(); // Initialize other components $this->init_components(); diff --git a/includes/class-hvac-query-monitor.php b/includes/class-hvac-query-monitor.php index b1bad261..2669a4e8 100644 --- a/includes/class-hvac-query-monitor.php +++ b/includes/class-hvac-query-monitor.php @@ -70,10 +70,10 @@ class HVAC_Query_Monitor { add_action('wp_ajax_hvac_clear_query_log', [__CLASS__, 'ajax_clear_log']); } - // WP-CLI integration - if (defined('WP_CLI') && WP_CLI) { - WP_CLI::add_command('hvac query-monitor', [__CLASS__, 'wp_cli_commands']); - } + // WP-CLI integration (disabled - method not implemented) + // if (defined('WP_CLI') && WP_CLI) { + // WP_CLI::add_command('hvac query-monitor', [__CLASS__, 'wp_cli_commands']); + // } } /** diff --git a/includes/class-hvac-registration.php b/includes/class-hvac-registration.php index bdc3fecd..789431c4 100644 --- a/includes/class-hvac-registration.php +++ b/includes/class-hvac-registration.php @@ -428,22 +428,54 @@ class HVAC_Registration {

Organization Headquarters

-
+ +
+ + + ' . esc_html($errors['org_headquarters_country']) . '

'; ?> +
+ +
+
+ + + + ' . esc_html($errors['org_headquarters_state']) . '

'; ?> + ' . esc_html($errors['org_headquarters_state_other']) . '

'; ?> +
' . esc_html($errors['org_headquarters_city']) . '

'; ?>
-
- - - ' . esc_html($errors['org_headquarters_state']) . '

'; ?> -
-
- - - ' . esc_html($errors['org_headquarters_country']) . '

'; ?> -
@@ -451,25 +483,23 @@ class HVAC_Registration {

Training Capabilities

- - What type of business are you? -
- 'business_type', 'hide_empty' => false]); - if (!is_wp_error($business_terms) && !empty($business_terms)) { - foreach ($business_terms as $term) { - echo ''; - } - } else { - // Fallback to hardcoded options if taxonomy not available - $business_types = ["Manufacturer", "Distributor", "Contractor", "Consultant", "Educator", "Government", "Other"]; - foreach ($business_types as $type) { - echo ''; - } - } - ?> -
- ' . esc_html($errors['business_type']) . '

'; ?> + + What best describes your business type? + + ' . esc_html($errors['business_type']) . '

'; ?>
@@ -477,25 +507,18 @@ class HVAC_Registration { Who do you offer training to? (Select all that apply)
'training_audience', 'hide_empty' => false]); $selected_audience = $data['training_audience'] ?? []; if (!is_array($selected_audience)) $selected_audience = []; // Ensure it's an array - if (!is_wp_error($audience_terms) && !empty($audience_terms)) { - foreach ($audience_terms as $term) { - echo ''; - } - } else { - // Fallback to hardcoded options if taxonomy not available - $audience_options = [ - "Anyone (open to the public)" => "Anyone (open to the public)", - "Industry professionals" => "Industry professionals", - "Internal staff in my company" => "Internal staff in my company", - "Registered students/members of my org/institution" => "Registered students/members of my org/institution" - ]; - foreach ($audience_options as $value => $label) { - echo ''; - } + // Use only the 4 specified options + $audience_options = [ + "Anyone (open to the public)", + "Industry professionals", + "Internal staff in my company", + "Registered students/members of my org/institution" + ]; + foreach ($audience_options as $option) { + echo ''; } ?>
@@ -1024,7 +1047,10 @@ class HVAC_Registration { 'business_website' => !empty($data['business_website']) ? esc_url_raw($data['business_website']) : '', 'business_description' => wp_kses_post($data['business_description']), 'org_headquarters_city' => !empty($data['org_headquarters_city']) ? sanitize_text_field($data['org_headquarters_city']) : '', - 'org_headquarters_state' => !empty($data['org_headquarters_state']) ? sanitize_text_field($data['org_headquarters_state']) : '', + // Use the 'Other' field value if state was 'Other', otherwise use the selected state + 'org_headquarters_state' => ($data['org_headquarters_state'] === 'Other' && !empty($data['org_headquarters_state_other'])) + ? sanitize_text_field($data['org_headquarters_state_other']) + : (!empty($data['org_headquarters_state']) ? sanitize_text_field($data['org_headquarters_state']) : ''), 'org_headquarters_country' => !empty($data['org_headquarters_country']) ? sanitize_text_field($data['org_headquarters_country']) : '', 'create_venue' => sanitize_text_field($data['create_venue']), // Should be 'Yes' or 'No' 'business_type' => sanitize_text_field($data['business_type']),