diff --git a/Status.md b/Status.md index 462545b5..7466d816 100644 --- a/Status.md +++ b/Status.md @@ -1,9 +1,9 @@ # HVAC Community Events Plugin - Current Status ## TEC Community Events Replacement Implementation -**Date**: January 27, 2025 +**Date**: September 28, 2025 **Current Branch**: feature/native-event-system -**Implementation Phase**: Security Hardening Complete - Phase 1 Critical Fixes Deployed +**Implementation Phase**: Event Edit Page Modernization Complete **Strategic Context**: TEC Community Events Extension Replacement (NOT TEC Core) --- @@ -43,6 +43,12 @@ - [x] **AI-Powered Event Population** - URL parsing, text extraction, intelligent form filling - [x] **Dynamic Searchable Selectors** - Real-time search for venues, organizers, categories - [x] **Modal Creation Forms** - Inline venue/organizer creation with role-based permissions +- [x] **EVENT EDIT PAGE MODERNIZATION** - Complete refactoring with feature parity +- [x] **Form Builder Edit Capabilities** - Extended with edit_event_form(), load_event_data(), populate_form_fields() +- [x] **Form Handler Update Methods** - Added update_event(), validate_update_permissions(), validation +- [x] **Template Modernization** - Replaced legacy iframe with native form builder integration +- [x] **Security Fixes** - Resolved nonce mismatches and permission validation +- [x] **Template Loading Fix** - Updated content injection for proper template routing - [x] **Authoritative Documentation** - Complete technical documentation created - [x] **Legacy Code Deprecation** - 27+ deprecated files marked for removal in v3.3 - [x] Strategic scope clarified (TEC Community Events only, not TEC Core) @@ -226,6 +232,6 @@ This implementation represents a targeted solution to specific TEC Community Eve --- -*Status last updated: September 24, 2025* +*Status last updated: September 28, 2025* *Implementation plan: TEC-COMMUNITY-EVENTS-REPLACEMENT-PLAN.md* *Ready for Week 1 implementation initiation* \ No newline at end of file diff --git a/docs/EDIT-PAGE-REFACTORING-ANALYSIS.md b/docs/EDIT-PAGE-REFACTORING-ANALYSIS.md new file mode 100644 index 00000000..122d2ea4 --- /dev/null +++ b/docs/EDIT-PAGE-REFACTORING-ANALYSIS.md @@ -0,0 +1,259 @@ +# Event Edit Page Refactoring Analysis + +**Date**: September 27, 2025 +**Analysis Tool**: Zen Refactor with GLM-4.5 +**Scope**: Modernization of `trainer/event/edit/?event_id=6420` to match create page patterns + +--- + +## Executive Summary + +The event edit page uses a legacy iframe-based architecture that lacks feature parity with the modernized create page. A comprehensive architectural overhaul is required to achieve consistency and provide users with the same advanced functionality across both create and edit workflows. + +**Total Issues Identified**: 14 refactoring opportunities +**Severity Breakdown**: 4 Critical, 5 High Priority, 4 Medium Priority, 1 Low Priority + +--- + +## Current Architecture Comparison + +### Edit Page (Legacy - REQUIRES REFACTORING) +```php +// page-tec-edit-event.php - Current Implementation +- Uses iframe embedding: `/events/network/edit/{id}/` +- No native form control +- Limited validation and error handling +- Cross-origin iframe limitations +- Basic styling and UX +``` + +### Create Page (Modern - TARGET PATTERN) +```php +// page-tec-create-event.php - Target Implementation +- Native HVAC_Event_Form_Builder integration +- HVAC_Event_Form_Handler for processing +- WordPress TinyMCE rich text editor +- AI-powered content generation +- Featured image upload with wp.media +- Searchable selectors with autocomplete +- Advanced options toggle functionality +- Modal venue/organizer creation +``` + +--- + +## Critical Issues (Immediate Action Required) + +### 🚨 Issue #1: Missing Edit Methods +**File**: `includes/class-hvac-event-form-builder.php` +**Problem**: Only has `create_event_form()` method, no edit capability +**Solution**: Add `edit_event_form($event_id, $config = [])` method +**Impact**: Blocks native form implementation for editing + +### 🚨 Issue #2: Missing Update Methods +**File**: `includes/class-hvac-event-form-handler.php` +**Problem**: Only has `create_event()` method, no update functionality +**Solution**: Add `update_event($event_id, $form_data)` method +**Impact**: Cannot process edit form submissions + +### 🚨 Issue #3: Legacy Architecture +**File**: `templates/page-tec-edit-event.php` +**Problem**: Uses iframe embedding instead of native form builder +**Solution**: Replace with native HVAC form builder integration +**Impact**: Prevents access to modern features and causes UX inconsistencies + +### 🚨 Issue #4: No Data Pre-population +**Files**: Form builder and handler classes +**Problem**: Cannot load existing event data into form fields +**Solution**: Implement event data loading and field pre-population +**Impact**: Users cannot see current values when editing + +--- + +## High Priority Feature Gaps + +### ⚠️ Issue #5: No AI Assistance +**Missing**: AI-powered content generation for event descriptions +**Implementation**: Integrate hvac-ai-assist.js with edit mode + +### ⚠️ Issue #6: No Featured Images +**Missing**: Featured image editing capability +**Implementation**: Add wp.media integration for image uploads + +### ⚠️ Issue #7: No Searchable Selectors +**Missing**: Autocomplete for venues/organizers/categories +**Implementation**: Add searchable selector components with pre-selected values + +### ⚠️ Issue #8: No Advanced Options +**Missing**: Timezone, capacity, cost toggle functionality +**Implementation**: Add advanced options toggle with field visibility controls + +### ⚠️ Issue #9: No Modal Creation +**Missing**: Inline venue/organizer creation +**Implementation**: Add modal forms for creating new entities during editing + +--- + +## Medium Priority UX Consistency Issues + +### 📋 Issue #10: No TinyMCE Editor +**Current**: Basic textarea for descriptions +**Target**: WordPress TinyMCE rich text editor with formatting + +### 📋 Issue #11: No Form Validation +**Current**: Basic validation via iframe +**Target**: Comprehensive input validation with real-time feedback + +### 📋 Issue #12: No Error Handling +**Current**: Basic error display +**Target**: Comprehensive error handling with user-friendly messages + +### 📋 Issue #13: Inconsistent Styling +**Current**: Different CSS patterns between create and edit pages +**Target**: Unified styling system across both pages + +--- + +## Implementation Strategy + +### Phase 1: Extend Core Classes (Week 1) + +#### 1.1 Extend HVAC_Event_Form_Builder +```php +// Add to class-hvac-event-form-builder.php +public function edit_event_form(int $event_id, array $config = []): self +public function load_event_data(int $event_id): array +public function populate_form_fields(array $event_data): self +``` + +#### 1.2 Extend HVAC_Event_Form_Handler +```php +// Add to class-hvac-event-form-handler.php +public static function update_event(int $event_id, array $form_data): int|WP_Error +public static function validate_update_permissions(int $event_id, int $user_id): bool +public static function get_event_data_for_editing(int $event_id): array|WP_Error +``` + +### Phase 2: Template Modernization (Week 2) + +#### 2.1 Replace iframe Architecture +- Remove iframe embedding from `page-tec-edit-event.php` +- Implement native form builder integration +- Add form submission processing + +#### 2.2 Add Modern Features +- AI assistance integration +- Featured image editing +- Searchable selectors with pre-selected values +- Advanced options toggle +- Modal creation forms + +#### 2.3 Ensure Feature Parity +- TinyMCE rich text editor +- Comprehensive validation +- Error handling and user feedback +- Consistent styling + +### Phase 3: Integration & Testing (Week 3) + +#### 3.1 URL Compatibility +- Maintain existing URL structure: `trainer/event/edit/?event_id=6420` +- Ensure backward compatibility with bookmarks and links + +#### 3.2 TEC Integration +- Verify tribe_events post type compatibility +- Test event metadata preservation +- Validate venue/organizer associations + +#### 3.3 User Experience Testing +- Test complete edit workflow +- Verify form validation and error handling +- Confirm feature parity with create page + +--- + +## Technical Requirements + +### Form Builder Extensions +```php +// Required methods for edit functionality +- edit_event_form(int $event_id, array $config = []): self +- load_event_data(int $event_id): array +- populate_form_fields(array $event_data): self +- set_edit_mode(bool $is_edit): self +- get_form_mode(): string +``` + +### Form Handler Extensions +```php +// Required methods for update processing +- update_event(int $event_id, array $form_data): int|WP_Error +- validate_update_permissions(int $event_id, int $user_id): bool +- get_event_data_for_editing(int $event_id): array|WP_Error +- validate_and_sanitize_update(array $form_data, int $event_id): array|WP_Error +``` + +### Template Requirements +- Native form builder integration +- Event data pre-population +- Form submission handling +- Success/error feedback +- Modern feature integration (AI, featured images, etc.) + +--- + +## Success Criteria + +### Technical Metrics +- [ ] Native form builder replaces iframe approach +- [ ] Complete feature parity with create page +- [ ] All 14 identified issues resolved +- [ ] Backward URL compatibility maintained +- [ ] TEC integration preserved + +### User Experience Metrics +- [ ] Consistent editing workflow with creation +- [ ] AI assistance available for content editing +- [ ] Featured image editing capability +- [ ] Advanced options accessible via toggle +- [ ] Real-time validation and error feedback + +### Performance Metrics +- [ ] No iframe cross-origin limitations +- [ ] Faster form loading and interaction +- [ ] Reduced complexity in form submission + +--- + +## Risk Assessment + +### Low Risk ✅ +- **Form Builder Extension**: Well-established patterns from create page +- **Template Modernization**: Clear target implementation exists +- **Feature Integration**: All components already functional on create page + +### Medium Risk ⚠️ +- **Data Migration**: Ensuring all existing event data loads correctly +- **URL Compatibility**: Maintaining backward compatibility during transition +- **User Training**: Users familiar with iframe approach may need guidance + +### High Risk 🚨 +- **TEC Integration**: Must preserve all event metadata and associations +- **Permission Validation**: Ensuring secure edit access controls +- **Data Integrity**: Preventing data loss during edit operations + +--- + +## Implementation Priority + +1. **Phase 1 (Critical)**: Extend form builder and handler classes +2. **Phase 2 (High)**: Replace template architecture and add modern features +3. **Phase 3 (Medium)**: Integration testing and URL compatibility + +**Estimated Timeline**: 3 weeks +**Resource Requirements**: 1 developer, access to staging environment +**Dependencies**: Completion of create page modernization (✅ Complete) + +--- + +*This analysis provides the complete roadmap for modernizing the event edit page to achieve feature parity with the create page while maintaining backward compatibility and TEC integration.* \ No newline at end of file diff --git a/includes/class-hvac-community-events.php b/includes/class-hvac-community-events.php index 70912eec..62561725 100644 --- a/includes/class-hvac-community-events.php +++ b/includes/class-hvac-community-events.php @@ -966,21 +966,23 @@ class HVAC_Community_Events { wp_safe_redirect(home_url('/training-login/?redirect=' . urlencode($_SERVER['REQUEST_URI']))); exit; } - - // Get event ID from URL - $event_id = isset($_GET['event_id']) ? (int) $_GET['event_id'] : 0; - - // Load and return the custom form + + // Load the modern template ob_start(); - ?> - -
Event ID:
-This is a test to confirm the content injection is working.
-If you see this, the template loading mechanism is working but needs the full form implementation.
-❌ Template not found: ' . esc_html($template_path) . '
'; + } + return ob_get_clean(); } return $content; diff --git a/includes/class-hvac-event-form-builder.php b/includes/class-hvac-event-form-builder.php index a6ad93ba..228d60ca 100644 --- a/includes/class-hvac-event-form-builder.php +++ b/includes/class-hvac-event-form-builder.php @@ -46,6 +46,27 @@ class HVAC_Event_Form_Builder extends HVAC_Form_Builder { */ private bool $template_mode_enabled = false; + /** + * Edit mode flag + * + * @var bool + */ + private bool $is_edit_mode = false; + + /** + * Event ID being edited (when in edit mode) + * + * @var int + */ + private int $editing_event_id = 0; + + /** + * Event data for pre-population + * + * @var array + */ + private array $event_data = []; + /** * Event-specific field defaults * @@ -228,6 +249,168 @@ class HVAC_Event_Form_Builder extends HVAC_Form_Builder { return $this; } + /** + * Create event edit form with pre-populated data + * + * @param int $event_id Event ID to edit + * @param array $config Form configuration options + * @return self + */ + public function edit_event_form(int $event_id, array $config = []): self { + // Load existing event data + $event_data = $this->load_event_data($event_id); + + if (is_wp_error($event_data)) { + // Add error field if event cannot be loaded + $this->add_field([ + 'type' => 'custom', + 'name' => 'event_load_error', + 'label' => 'Error', + 'custom_html' => '❌ ' . esc_html($event_data->get_error_message()) . '