- Implement singleton pattern for HVAC_Enhanced_Settings to prevent duplicate initialization - Fix jQuery selector error by checking for valid hash selectors before using $(href) - Add default email templates with professional copy for trainer notifications - Update plugin version to 1.0.1 for cache busting - Remove duplicate Enhanced Settings initialization from HVAC_Community_Events - Add force cache refresh suffix to admin scripts This resolves the duplicate content issue on email templates page and fixes JavaScript errors in the admin interface. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4.6 KiB
4.6 KiB
HVAC Community Events - Refactoring Guide
Overview
This document describes the refactoring of the HVAC Community Events plugin to follow WordPress best practices for better maintainability and scalability.
Architecture Changes
Before (Monolithic Structure)
hvac-community-events.php (4000+ lines)
├── All page definitions
├── Activation logic
├── Redirect handling
└── Mixed responsibilities
After (Modular Structure)
hvac-community-events.php (30 lines - bootstrap only)
├── includes/
│ ├── class-hvac-plugin.php (Main plugin orchestrator)
│ ├── class-hvac-activator.php (Activation logic)
│ ├── class-hvac-deactivator.php (Deactivation logic)
│ ├── class-hvac-page-manager.php (Page creation/management)
│ └── class-hvac-template-loader.php (Template handling)
└── templates/
├── content/ (Gutenberg block content)
├── status/ (Status page templates)
└── pages/ (Other page templates)
Key Improvements
1. Separation of Concerns
- Page Management: All page-related logic moved to
HVAC_Page_Manager - Template Loading: Dedicated
HVAC_Template_Loaderclass - Activation: Clean
HVAC_Activatorclass - Content Storage: Page content in separate HTML files
2. Template Override System
Themes can now override plugin templates by copying them to:
/your-theme/hvac-community-events/[template-path]
3. Dynamic Content Placeholders
Content files support placeholders:
{home_url}- Site home URL{logout_url}- Logout URL{login_url}- Login URL{site_name}- Site name{support_email}- Support email
4. Hooks and Filters
New action hooks:
hvac_trainer_pending_after_content- After pending page contenthvac_trainer_disabled_after_content- After disabled page content
Migration Steps
1. Backup Current Plugin
cp -r hvac-community-events hvac-community-events-backup
2. Replace Main Plugin File
mv hvac-community-events-new.php hvac-community-events.php
3. Test Activation
- Deactivate plugin
- Activate plugin
- Verify all pages are created
4. Update Custom Code
If you have custom code referencing the old structure:
Old way:
// Pages were hardcoded in main file
$pages = [...]; // 200+ lines of page definitions
New way:
// Use the page manager
$page_config = HVAC_Page_Manager::get_page_config('trainer-account-pending');
Benefits
- Maintainability: Each component has a single responsibility
- Testability: Classes can be unit tested independently
- Extensibility: Easy to add new pages or modify existing ones
- Performance: Only loads what's needed
- Standards: Follows WordPress coding standards and best practices
File Locations
Status Page Content
/templates/content/trainer-account-pending.html/templates/content/trainer-account-disabled.html
Status Page Templates
/templates/status/trainer-account-pending.php/templates/status/trainer-account-disabled.php
Core Classes
/includes/class-hvac-plugin.php- Main plugin class/includes/class-hvac-page-manager.php- Page management/includes/class-hvac-template-loader.php- Template loading/includes/class-hvac-activator.php- Activation logic/includes/class-hvac-deactivator.php- Deactivation logic
Customization
Adding a New Page
- Add page definition to
HVAC_Page_Manager::$pages - Create content file in
/templates/content/(optional) - Create template file in
/templates/(optional)
Modifying Page Content
- Edit the HTML file in
/templates/content/ - Or override in theme:
/your-theme/hvac-community-events/content/[filename]
Custom Templates
- Copy template from plugin to theme
- Modify as needed
- Plugin will automatically use theme version
Testing Checklist
- Plugin activates without errors
- All pages are created correctly
- Status pages show correct content
- Template overrides work in theme
- Access control still functions
- No PHP errors in logs
- Performance is maintained
Rollback Plan
If issues occur:
- Deactivate plugin
- Restore backup:
cp -r hvac-community-events-backup/* hvac-community-events/ - Reactivate plugin
Future Enhancements
- Block Patterns: Register Gutenberg block patterns for reusable layouts
- REST API: Add endpoints for page management
- CLI Commands: WP-CLI commands for page operations
- Unit Tests: PHPUnit tests for all classes
- Composer: Autoloading and dependency management