diff --git a/CLAUDE.md b/CLAUDE.md index 5d55c393..30ba006c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -25,5 +25,6 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co - **Trainer Page Redirects and Admin Bar Removal (2025-07-23)**: Added 301 redirects from /trainer/ to /trainer/dashboard/ and /master-trainer/ to /master-trainer/dashboard/. Removed admin bar hiding code as it's now handled by The Events Calendar plugin. Updated toolbar Dashboard link to use /trainer/dashboard/. - **Production Error Fixes (2025-07-24)**: Fixed production logging issues: Removed all debug error_log statements, added duplicate checking for OAuth query vars to prevent 153+ additions, optimized admin script loading to specific page only. Significantly reduces log noise and improves performance. - **Production Deployment Support (2025-07-24)**: Updated deployment infrastructure to support both staging and production environments. Use `scripts/deploy.sh staging` for staging deployments and `scripts/deploy.sh production` only when explicitly requested by the user. Production deployments require double confirmation to prevent accidental deployment. IMPORTANT: Only deploy to production when the user explicitly asks for production deployment. +- **Plugin Architecture Refactoring (2025-07-28)**: Implemented modular architecture with single-responsibility classes. Created HVAC_Shortcodes for centralized shortcode management, HVAC_Scripts_Styles for asset management, and HVAC_Route_Manager for URL routing. Eliminated duplicate functionality between HVAC_Plugin and HVAC_Community_Events. All components now use singleton pattern to prevent duplicate initialization. Fixed jQuery selector errors and duplicate content issues. See docs/ARCHITECTURE.md for details. [... rest of the existing content remains unchanged ...] \ No newline at end of file diff --git a/README.md b/README.md index a13a2236..70565caa 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,20 @@ Network Events is a WordPress plugin that extends The Events Calendar suite to c - Integration with The Events Calendar suite (✅ Verified functional) - Master dashboard with trainer analytics (✅ Verified functional) +## Architecture + +The plugin follows a modular architecture with single-responsibility classes: + +### Core Components +- **HVAC_Plugin**: Main plugin controller +- **HVAC_Shortcodes**: Centralized shortcode management +- **HVAC_Scripts_Styles**: Asset management +- **HVAC_Route_Manager**: URL routing and redirects +- **HVAC_Template_Loader**: Template handling +- **HVAC_Page_Manager**: WordPress page creation + +See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for detailed architecture documentation. + ## Requirements ### WordPress Environment diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md new file mode 100644 index 00000000..b4aad625 --- /dev/null +++ b/docs/ARCHITECTURE.md @@ -0,0 +1,190 @@ +# HVAC Community Events - Plugin Architecture + +## Overview + +The HVAC Community Events plugin follows a modular, single-responsibility architecture designed for maintainability and extensibility. + +## Core Architecture Components + +### 1. HVAC_Plugin (Main Controller) +- **Location**: `/includes/class-hvac-plugin.php` +- **Purpose**: Main plugin initialization and coordination +- **Responsibilities**: + - Plugin activation/deactivation + - Loading dependencies + - Initializing core components + - Hook registration + +### 2. HVAC_Shortcodes +- **Location**: `/includes/class-hvac-shortcodes.php` +- **Purpose**: Centralized shortcode management +- **Responsibilities**: + - Register all plugin shortcodes + - Handle shortcode callbacks + - Manage shortcode attributes +- **Key Shortcodes**: + - `[hvac_dashboard]` - Trainer dashboard + - `[hvac_master_dashboard]` - Master trainer dashboard + - `[hvac_trainer_registration]` - Registration form + - `[hvac_community_login]` - Login form + - `[hvac_manage_event]` - Event management + - `[hvac_certificate_reports]` - Certificate reports + +### 3. HVAC_Scripts_Styles +- **Location**: `/includes/class-hvac-scripts-styles.php` +- **Purpose**: Asset management +- **Responsibilities**: + - Frontend script/style enqueuing + - Admin script/style enqueuing + - Script localization + - Cache busting + +### 4. HVAC_Route_Manager +- **Location**: `/includes/class-hvac-route-manager.php` +- **Purpose**: URL routing and redirects +- **Responsibilities**: + - Legacy URL redirects + - Parent page redirects + - Custom rewrite rules + - Query var registration + +### 5. HVAC_Template_Loader +- **Location**: `/includes/class-hvac-template-loader.php` +- **Purpose**: Template handling +- **Responsibilities**: + - Load custom templates + - Template hierarchy + - Theme compatibility + +### 6. HVAC_Page_Manager +- **Location**: `/includes/class-hvac-page-manager.php` +- **Purpose**: WordPress page management +- **Responsibilities**: + - Create plugin pages + - Manage page hierarchy + - Set page templates + +## Feature Components + +### Authentication & Access Control +- **HVAC_Access_Control**: Page access restrictions +- **HVAC_Roles**: User role management +- **HVAC_Trainer_Status**: Trainer approval status + +### Event Management +- **HVAC_Manage_Event**: Event creation/editing +- **HVAC_Event_Summary**: Event details display +- **Event_Form_Handler**: Form processing + +### Dashboards +- **HVAC_Dashboard**: Trainer dashboard +- **HVAC_Master_Dashboard**: Master trainer dashboard +- **HVAC_Dashboard_Data**: Dashboard data processing + +### Certificate System +- **HVAC_Certificate_Manager**: Certificate generation +- **HVAC_Certificate_Security**: Security measures +- **HVAC_Certificate_URL_Handler**: URL processing + +### Communication +- **HVAC_Communication_Templates**: Email templates +- **HVAC_Communication_Scheduler**: Automated emails + +## Design Patterns + +### Singleton Pattern +Used for classes that should have only one instance: +- HVAC_Plugin +- HVAC_Shortcodes +- HVAC_Scripts_Styles +- HVAC_Route_Manager +- HVAC_Help_System +- HVAC_Certificate_Security + +### Hook-Based Architecture +WordPress actions and filters are used extensively: +- `init` - Component initialization +- `wp_enqueue_scripts` - Frontend assets +- `admin_enqueue_scripts` - Admin assets +- `template_redirect` - Access control + +## File Structure + +``` +hvac-community-events/ +├── hvac-community-events.php # Main plugin file +├── includes/ +│ ├── class-hvac-plugin.php # Main controller +│ ├── class-hvac-shortcodes.php # Shortcode manager +│ ├── class-hvac-scripts-styles.php # Asset manager +│ ├── class-hvac-route-manager.php # URL routing +│ ├── class-hvac-template-loader.php # Templates +│ ├── class-hvac-page-manager.php # Page creation +│ ├── class-hvac-access-control.php # Access control +│ ├── admin/ # Admin classes +│ ├── certificates/ # Certificate system +│ └── communication/ # Email system +├── templates/ # Template files +├── assets/ +│ ├── css/ # Stylesheets +│ └── js/ # JavaScript +└── docs/ # Documentation +``` + +## Initialization Flow + +1. `hvac-community-events.php` loads +2. `HVAC_Plugin::instance()` singleton created +3. Core components initialized: + - HVAC_Shortcodes + - HVAC_Scripts_Styles + - HVAC_Route_Manager + - HVAC_Template_Loader +4. Feature components loaded +5. Hooks registered +6. Ready for requests + +## Database Tables + +- `{prefix}_hvac_certificates` - Certificate records +- `{prefix}_hvac_communication_schedules` - Email schedules +- `{prefix}_hvac_google_sheets_auth` - Google Sheets tokens + +## Key URLs + +### Trainer Pages +- `/trainer/dashboard/` - Main dashboard +- `/trainer/registration/` - Registration form +- `/trainer/event/manage/` - Create/edit events +- `/trainer/certificate-reports/` - View certificates + +### Master Trainer Pages +- `/master-trainer/dashboard/` - Master dashboard +- `/master-trainer/google-sheets/` - Google Sheets integration + +### Public Pages +- `/training-login/` - Login page +- `/trainer/registration/` - Public registration + +## Security + +- Capability-based access control +- Nonce verification for forms +- Prepared SQL statements +- Escaped output +- Sanitized input + +## Performance Optimizations + +- Singleton patterns prevent duplicate initialization +- Assets loaded only on relevant pages +- Database queries optimized +- Caching implemented where appropriate + +## Future Improvements + +1. Implement PSR-4 autoloading +2. Add unit test coverage +3. Implement dependency injection container +4. Add REST API endpoints +5. Enhance caching strategies \ No newline at end of file diff --git a/includes/class-hvac-access-control.php b/includes/class-hvac-access-control.php index 78157969..893664b4 100644 --- a/includes/class-hvac-access-control.php +++ b/includes/class-hvac-access-control.php @@ -61,6 +61,12 @@ class HVAC_Access_Control { // Get current page path $current_path = trim( parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ), '/' ); + // Check if this is a legacy URL that will be redirected + if ( $this->is_legacy_url( $current_path ) ) { + // Allow the redirect to happen first + return; + } + // Check if this is a public page if ( $this->is_public_page( $current_path ) ) { return; @@ -72,6 +78,24 @@ class HVAC_Access_Control { } } + /** + * Check if current URL is a legacy URL that should be redirected + * + * @param string $path Current page path + * @return bool + */ + private function is_legacy_url( $path ) { + // Get the route manager instance + if ( ! class_exists( 'HVAC_Route_Manager' ) ) { + return false; + } + + $route_manager = HVAC_Route_Manager::instance(); + + // Check if this path needs a redirect + return $route_manager->needs_redirect( $path ) !== false; + } + /** * Check if current page is public * diff --git a/scripts/assign-page-templates.sh b/scripts/assign-page-templates.sh new file mode 100755 index 00000000..ff1e4b01 --- /dev/null +++ b/scripts/assign-page-templates.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +echo "=== Assigning Page Templates ===" + +ssh roodev@146.190.76.204 << 'ENDSSH' +cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html + +# Function to set page template +set_page_template() { + local page_id="$1" + local template="$2" + + echo "Setting template '$template' for page ID $page_id..." + wp post meta update "$page_id" "_wp_page_template" "$template" +} + +# Master Dashboard - ID 5347 +set_page_template 5347 "page-master-dashboard.php" + +# Trainer Registration - ID 5334 +set_page_template 5334 "page-trainer-registration.php" + +# Trainer Dashboard - ID 5333 +set_page_template 5333 "page-trainer-dashboard.php" + +# Trainer Profile - ID 5335 +set_page_template 5335 "page-trainer-profile.php" + +# Clear cache +wp cache flush +wp breeze purge --cache=all + +echo -e "\n✅ Templates assigned and cache cleared" +ENDSSH \ No newline at end of file diff --git a/scripts/check-page-templates.sh b/scripts/check-page-templates.sh new file mode 100755 index 00000000..88c3c06e --- /dev/null +++ b/scripts/check-page-templates.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +echo "=== Checking Page Templates ===" + +ssh roodev@146.190.76.204 << 'ENDSSH' +cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html + +echo "Checking page templates for HVAC pages..." + +# Check master dashboard +echo -e "\n--- Master Dashboard ---" +wp db query "SELECT p.ID, p.post_title, p.post_name, pm.meta_value as template FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_wp_page_template' WHERE p.post_name='dashboard' AND p.post_parent=(SELECT ID FROM wp_posts WHERE post_name='master-trainer' AND post_type='page') AND p.post_type='page'" + +# Check trainer registration +echo -e "\n--- Trainer Registration ---" +wp db query "SELECT p.ID, p.post_title, p.post_name, pm.meta_value as template FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_wp_page_template' WHERE p.post_name='registration' AND p.post_parent=(SELECT ID FROM wp_posts WHERE post_name='trainer' AND post_type='page') AND p.post_type='page'" + +# Check all pages with 'trainer' in the title +echo -e "\n--- All Trainer-Related Pages ---" +wp db query "SELECT p.ID, p.post_title, p.post_name, pm.meta_value as template FROM wp_posts p LEFT JOIN wp_postmeta pm ON p.ID = pm.post_id AND pm.meta_key = '_wp_page_template' WHERE p.post_title LIKE '%trainer%' AND p.post_type='page' ORDER BY p.ID" + +echo -e "\n✅ Complete" +ENDSSH \ No newline at end of file diff --git a/scripts/fix-page-shortcodes.sh b/scripts/fix-page-shortcodes.sh new file mode 100755 index 00000000..9f855277 --- /dev/null +++ b/scripts/fix-page-shortcodes.sh @@ -0,0 +1,68 @@ +#!/bin/bash + +# Fix Page Shortcodes Script +# Updates WordPress pages to include their respective shortcodes + +echo "=== Fixing Page Shortcodes ===" + +# Define pages and their shortcodes +declare -A page_shortcodes=( + ["trainer/dashboard"]="[hvac_dashboard]" + ["master-trainer/dashboard"]="[hvac_master_dashboard]" + ["trainer/registration"]="[hvac_trainer_registration]" + ["trainer/my-profile"]="[hvac_trainer_profile]" + ["trainer/event/manage"]="[hvac_manage_event]" + ["trainer/event/summary"]="[hvac_event_summary]" + ["trainer/certificate-reports"]="[hvac_certificate_reports]" + ["trainer/generate-certificates"]="[hvac_generate_certificates]" + ["trainer/email-attendees"]="[hvac_email_attendees]" + ["trainer/communication-templates"]="[hvac_communication_templates]" + ["trainer/communication-schedules"]="[hvac_communication_schedules]" + ["master-trainer/google-sheets"]="[hvac_google_sheets]" +) + +# SSH to staging and update pages +ssh roodev@146.190.76.204 << 'ENDSSH' +cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html + +# Function to update page content +update_page_content() { + local slug="$1" + local shortcode="$2" + + echo "Updating $slug with shortcode $shortcode..." + + # Get page ID by path + page_id=$(wp post list --post_type=page --pagename="$slug" --field=ID --format=ids) + + if [ -n "$page_id" ]; then + # Update page content with shortcode + wp post update "$page_id" --post_content="$shortcode" + echo "✅ Updated page $slug (ID: $page_id)" + else + echo "❌ Page not found: $slug" + fi +} + +# Update each page +update_page_content "trainer-dashboard" "[hvac_dashboard]" +update_page_content "master-dashboard" "[hvac_master_dashboard]" +update_page_content "trainer-registration" "[hvac_trainer_registration]" +update_page_content "trainer-profile" "[hvac_trainer_profile]" +update_page_content "manage-event" "[hvac_manage_event]" +update_page_content "event-summary" "[hvac_event_summary]" +update_page_content "certificate-reports" "[hvac_certificate_reports]" +update_page_content "generate-certificates" "[hvac_generate_certificates]" +update_page_content "email-attendees" "[hvac_email_attendees]" +update_page_content "communication-templates" "[hvac_communication_templates]" +update_page_content "communication-schedules" "[hvac_communication_schedules]" +update_page_content "google-sheets" "[hvac_google_sheets]" + +# Clear cache +wp cache flush +wp breeze purge --all + +echo "✅ Page shortcodes fixed and cache cleared" +ENDSSH + +echo "=== Script Complete ===" \ No newline at end of file diff --git a/scripts/list-and-fix-pages.sh b/scripts/list-and-fix-pages.sh new file mode 100755 index 00000000..bd6edeac --- /dev/null +++ b/scripts/list-and-fix-pages.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +echo "=== Listing and Fixing HVAC Pages ===" + +ssh roodev@146.190.76.204 << 'ENDSSH' +cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html + +echo "=== Current HVAC Pages ===" +wp post list --post_type=page --meta_key=_wp_page_template --meta_value='hvac%' --fields=ID,post_title,post_name,post_content --format=table + +echo -e "\n=== Searching for HVAC pages by title ===" +wp post list --post_type=page --s="trainer" --fields=ID,post_title,post_name,post_content --format=table + +echo -e "\n=== Searching for master pages ===" +wp post list --post_type=page --s="master" --fields=ID,post_title,post_name,post_content --format=table + +echo -e "\n=== Finding pages by URL path ===" +# Find trainer dashboard page +trainer_dash_id=$(wp db query "SELECT ID FROM wp_posts WHERE post_name='dashboard' AND post_parent=(SELECT ID FROM wp_posts WHERE post_name='trainer' AND post_type='page') AND post_type='page'" --skip-column-names) +if [ -n "$trainer_dash_id" ]; then + echo "Found trainer dashboard page ID: $trainer_dash_id" + wp post update "$trainer_dash_id" --post_content="[hvac_dashboard]" + echo "✅ Updated trainer dashboard" +fi + +# Find master dashboard page +master_dash_id=$(wp db query "SELECT ID FROM wp_posts WHERE post_name='dashboard' AND post_parent=(SELECT ID FROM wp_posts WHERE post_name='master-trainer' AND post_type='page') AND post_type='page'" --skip-column-names) +if [ -n "$master_dash_id" ]; then + echo "Found master dashboard page ID: $master_dash_id" + wp post update "$master_dash_id" --post_content="[hvac_master_dashboard]" + echo "✅ Updated master dashboard" +fi + +# Find registration page +registration_id=$(wp db query "SELECT ID FROM wp_posts WHERE post_name='registration' AND post_parent=(SELECT ID FROM wp_posts WHERE post_name='trainer' AND post_type='page') AND post_type='page'" --skip-column-names) +if [ -n "$registration_id" ]; then + echo "Found registration page ID: $registration_id" + wp post update "$registration_id" --post_content="[hvac_trainer_registration]" + echo "✅ Updated registration page" +fi + +# Clear cache +wp cache flush +wp breeze purge --cache=all + +echo -e "\n✅ Script complete" +ENDSSH \ No newline at end of file diff --git a/templates/page-master-dashboard.php b/templates/page-master-dashboard.php new file mode 100644 index 00000000..33edd813 --- /dev/null +++ b/templates/page-master-dashboard.php @@ -0,0 +1,12 @@ +