- 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>
		
			
				
	
	
		
			360 lines
		
	
	
		
			No EOL
		
	
	
		
			12 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			360 lines
		
	
	
		
			No EOL
		
	
	
		
			12 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| /**
 | |
|  * Page Manager for HVAC Community Events
 | |
|  *
 | |
|  * Handles creation and management of plugin pages following WordPress best practices
 | |
|  *
 | |
|  * @package HVAC_Community_Events
 | |
|  * @since 1.0.0
 | |
|  */
 | |
| 
 | |
| if (!defined('ABSPATH')) {
 | |
|     exit;
 | |
| }
 | |
| 
 | |
| /**
 | |
|  * HVAC_Page_Manager class
 | |
|  */
 | |
| class HVAC_Page_Manager {
 | |
|     
 | |
|     /**
 | |
|      * Page definitions
 | |
|      * 
 | |
|      * @var array
 | |
|      */
 | |
|     private static $pages = [
 | |
|         // Public pages
 | |
|         'training-login' => [
 | |
|             'title' => 'Trainer Login',
 | |
|             'template' => 'page-trainer-login.php',
 | |
|             'public' => true,
 | |
|             'parent' => null,
 | |
|             'capability' => null
 | |
|         ],
 | |
|         
 | |
|         // Trainer pages
 | |
|         'trainer' => [
 | |
|             'title' => 'Trainer',
 | |
|             'template' => null,
 | |
|             'public' => false,
 | |
|             'parent' => null,
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/dashboard' => [
 | |
|             'title' => 'Trainer Dashboard',
 | |
|             'template' => 'page-trainer-dashboard.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/registration' => [
 | |
|             'title' => 'Trainer Registration',
 | |
|             'template' => 'page-trainer-registration.php',
 | |
|             'public' => true,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => null
 | |
|         ],
 | |
|         'trainer/my-profile' => [
 | |
|             'title' => 'Trainer Profile',
 | |
|             'template' => 'page-trainer-profile.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/event' => [
 | |
|             'title' => 'Event',
 | |
|             'template' => null,
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/event/manage' => [
 | |
|             'title' => 'Manage Event',
 | |
|             'template' => 'page-manage-event.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer/event',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/event/summary' => [
 | |
|             'title' => 'Event Summary',
 | |
|             'template' => 'page-event-summary.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer/event',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         
 | |
|         // Status pages
 | |
|         'trainer-account-pending' => [
 | |
|             'title' => 'Account Pending Approval',
 | |
|             'template' => 'status/trainer-account-pending.php',
 | |
|             'public' => false,
 | |
|             'parent' => null,
 | |
|             'capability' => 'read',
 | |
|             'content_file' => 'content/trainer-account-pending.html'
 | |
|         ],
 | |
|         'trainer-account-disabled' => [
 | |
|             'title' => 'Account Access Restricted',
 | |
|             'template' => 'status/trainer-account-disabled.php',
 | |
|             'public' => false,
 | |
|             'parent' => null,
 | |
|             'capability' => 'read',
 | |
|             'content_file' => 'content/trainer-account-disabled.html'
 | |
|         ],
 | |
|         
 | |
|         // Certificate pages
 | |
|         'trainer/certificate-reports' => [
 | |
|             'title' => 'Certificate Reports',
 | |
|             'template' => 'page-certificate-reports.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/generate-certificates' => [
 | |
|             'title' => 'Generate Certificates',
 | |
|             'template' => 'page-generate-certificates.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         
 | |
|         // Communication pages
 | |
|         'trainer/email-attendees' => [
 | |
|             'title' => 'Email Attendees',
 | |
|             'template' => 'page-email-attendees.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/communication-templates' => [
 | |
|             'title' => 'Communication Templates',
 | |
|             'template' => 'page-communication-templates.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/communication-schedules' => [
 | |
|             'title' => 'Communication Schedules',
 | |
|             'template' => 'page-communication-schedules.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         
 | |
|         // Master trainer pages
 | |
|         'master-trainer' => [
 | |
|             'title' => 'Master Trainer',
 | |
|             'template' => null,
 | |
|             'public' => false,
 | |
|             'parent' => null,
 | |
|             'capability' => 'hvac_master_trainer'
 | |
|         ],
 | |
|         'master-trainer/dashboard' => [
 | |
|             'title' => 'Master Dashboard',
 | |
|             'template' => 'page-master-dashboard.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'master-trainer',
 | |
|             'capability' => 'hvac_master_trainer'
 | |
|         ],
 | |
|         'master-trainer/certificate-fix' => [
 | |
|             'title' => 'Certificate System Diagnostics',
 | |
|             'template' => 'page-certificate-fix.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'master-trainer',
 | |
|             'capability' => 'hvac_master_trainer'
 | |
|         ],
 | |
|         'master-trainer/google-sheets' => [
 | |
|             'title' => 'Google Sheets Integration',
 | |
|             'template' => 'page-google-sheets.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'master-trainer',
 | |
|             'capability' => 'hvac_master_trainer'
 | |
|         ],
 | |
|         
 | |
|         // Other pages
 | |
|         'trainer/documentation' => [
 | |
|             'title' => 'Trainer Documentation',
 | |
|             'template' => 'page-documentation.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'trainer/attendee-profile' => [
 | |
|             'title' => 'Attendee Profile',
 | |
|             'template' => 'page-attendee-profile.php',
 | |
|             'public' => false,
 | |
|             'parent' => 'trainer',
 | |
|             'capability' => 'hvac_trainer'
 | |
|         ],
 | |
|         'registration-pending' => [
 | |
|             'title' => 'Registration Pending',
 | |
|             'template' => 'page-registration-pending.php',
 | |
|             'public' => false,
 | |
|             'parent' => null,
 | |
|             'capability' => null,
 | |
|             'content_file' => 'content/registration-pending.html'
 | |
|         ]
 | |
|     ];
 | |
|     
 | |
|     /**
 | |
|      * Create all required pages
 | |
|      * 
 | |
|      * @return void
 | |
|      */
 | |
|     public static function create_pages() {
 | |
|         HVAC_Logger::info('Starting page creation process', 'Page Manager');
 | |
|         
 | |
|         foreach (self::$pages as $slug => $config) {
 | |
|             self::create_page($slug, $config);
 | |
|         }
 | |
|         
 | |
|         // Flush rewrite rules after creating all pages
 | |
|         flush_rewrite_rules();
 | |
|         HVAC_Logger::info('Completed page creation process', 'Page Manager');
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Create a single page
 | |
|      * 
 | |
|      * @param string $slug Page slug
 | |
|      * @param array $config Page configuration
 | |
|      * @return int|false Page ID or false on failure
 | |
|      */
 | |
|     private static function create_page($slug, $config) {
 | |
|         // Check if page already exists
 | |
|         $existing_page = get_page_by_path($slug);
 | |
|         if ($existing_page) {
 | |
|             HVAC_Logger::info("Page already exists: {$slug}", 'Page Manager');
 | |
|             return $existing_page->ID;
 | |
|         }
 | |
|         
 | |
|         // Prepare page data
 | |
|         $page_data = [
 | |
|             'post_title'    => $config['title'],
 | |
|             'post_name'     => basename($slug),
 | |
|             'post_content'  => self::get_page_content($slug, $config),
 | |
|             'post_status'   => 'publish',
 | |
|             'post_type'     => 'page',
 | |
|             'post_author'   => 1,
 | |
|             'comment_status' => 'closed',
 | |
|             'ping_status'   => 'closed'
 | |
|         ];
 | |
|         
 | |
|         // Set parent page if specified
 | |
|         if (!empty($config['parent'])) {
 | |
|             $parent_page = get_page_by_path($config['parent']);
 | |
|             if ($parent_page) {
 | |
|                 $page_data['post_parent'] = $parent_page->ID;
 | |
|             }
 | |
|         }
 | |
|         
 | |
|         // Create the page
 | |
|         $page_id = wp_insert_post($page_data);
 | |
|         
 | |
|         if (is_wp_error($page_id)) {
 | |
|             HVAC_Logger::error("Failed to create page: {$slug} - " . $page_id->get_error_message(), 'Page Manager');
 | |
|             return false;
 | |
|         }
 | |
|         
 | |
|         // Set page template if specified
 | |
|         if (!empty($config['template'])) {
 | |
|             update_post_meta($page_id, '_wp_page_template', $config['template']);
 | |
|         }
 | |
|         
 | |
|         // Set page capabilities if specified
 | |
|         if (!empty($config['capability'])) {
 | |
|             update_post_meta($page_id, '_hvac_required_capability', $config['capability']);
 | |
|         }
 | |
|         
 | |
|         HVAC_Logger::info("Created page: {$slug} (ID: {$page_id})", 'Page Manager');
 | |
|         return $page_id;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Get page content
 | |
|      * 
 | |
|      * @param string $slug Page slug
 | |
|      * @param array $config Page configuration
 | |
|      * @return string Page content
 | |
|      */
 | |
|     private static function get_page_content($slug, $config) {
 | |
|         // If content file is specified, load it
 | |
|         if (!empty($config['content_file'])) {
 | |
|             $content_path = HVAC_PLUGIN_DIR . 'templates/' . $config['content_file'];
 | |
|             if (file_exists($content_path)) {
 | |
|                 $content = file_get_contents($content_path);
 | |
|                 
 | |
|                 // Replace placeholders
 | |
|                 $replacements = [
 | |
|                     '{home_url}' => home_url(),
 | |
|                     '{logout_url}' => wp_logout_url(home_url()),
 | |
|                     '{login_url}' => home_url('/training-login/'),
 | |
|                     '{site_name}' => get_bloginfo('name'),
 | |
|                     '{support_email}' => get_option('hvac_support_email', 'support@upskillevents.com')
 | |
|                 ];
 | |
|                 
 | |
|                 $content = str_replace(array_keys($replacements), array_values($replacements), $content);
 | |
|                 
 | |
|                 return $content;
 | |
|             }
 | |
|         }
 | |
|         
 | |
|         // For pages with templates, use a placeholder
 | |
|         if (!empty($config['template'])) {
 | |
|             return '<!-- This page uses a custom template -->';
 | |
|         }
 | |
|         
 | |
|         // Default content for parent pages
 | |
|         return '';
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Get page definition by slug
 | |
|      * 
 | |
|      * @param string $slug Page slug
 | |
|      * @return array|null Page configuration or null if not found
 | |
|      */
 | |
|     public static function get_page_config($slug) {
 | |
|         return isset(self::$pages[$slug]) ? self::$pages[$slug] : null;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Check if a page requires authentication
 | |
|      * 
 | |
|      * @param string $slug Page slug
 | |
|      * @return bool
 | |
|      */
 | |
|     public static function requires_auth($slug) {
 | |
|         $config = self::get_page_config($slug);
 | |
|         return $config && !empty($config['capability']);
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Get required capability for a page
 | |
|      * 
 | |
|      * @param string $slug Page slug
 | |
|      * @return string|null Required capability or null if none
 | |
|      */
 | |
|     public static function get_required_capability($slug) {
 | |
|         $config = self::get_page_config($slug);
 | |
|         return $config ? $config['capability'] : null;
 | |
|     }
 | |
|     
 | |
|     /**
 | |
|      * Delete all plugin pages
 | |
|      * 
 | |
|      * @return void
 | |
|      */
 | |
|     public static function delete_pages() {
 | |
|         HVAC_Logger::info('Starting page deletion process', 'Page Manager');
 | |
|         
 | |
|         foreach (self::$pages as $slug => $config) {
 | |
|             $page = get_page_by_path($slug);
 | |
|             if ($page) {
 | |
|                 wp_delete_post($page->ID, true);
 | |
|                 HVAC_Logger::info("Deleted page: {$slug}", 'Page Manager');
 | |
|             }
 | |
|         }
 | |
|         
 | |
|         HVAC_Logger::info('Completed page deletion process', 'Page Manager');
 | |
|     }
 | |
| } |