upskill-event-manager/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/hvac-community-events.php
bengizmo 00ca47abcb fix: Resolve Master Dashboard CSS loading and styling issues
Major fixes implemented to resolve CSS issues on the master dashboard:

1. **Missing Header/Footer Calls - FIXED**
   - Added get_header() call to master dashboard template
   - Added get_footer() call to master dashboard template
   - This fixes CSS files not loading because wp_enqueue_scripts wasn't triggered

2. **Missing CSS Styles - FIXED**
   - Added 200+ lines of master dashboard specific CSS styles
   - Included styles for .dashboard-section, .section-title, .events-filters
   - Added styles for .trainers-table, .events-table, .pagination-container
   - Added responsive design breakpoints for mobile/tablet

3. **CSS Variable References - FIXED**
   - Updated all CSS variables to match harmonized framework
   - Changed --hvac-spacing-lg to --hvac-spacing-6
   - Changed --hvac-border-radius to --hvac-radius-md
   - Changed --hvac-text to --hvac-theme-text

4. **AJAX Handler - FIXED**
   - Moved inline AJAX handling to proper WordPress hooks
   - Added wp_ajax_hvac_master_dashboard_events action
   - Added proper nonce verification and permission checks
   - Removed inline AJAX code from template

5. **Template Structure - FIXED**
   - Fixed missing </main> closing tag
   - Ensured proper HTML structure with header/footer integration
   - Added proper WordPress template loading pattern

Technical improvements:
- Master dashboard now loads all CSS files correctly
- Proper WordPress template structure implemented
- AJAX functionality follows WordPress standards
- Responsive design for all screen sizes
- Full compatibility with Astra theme CSS variables

All master dashboard styling issues are now resolved.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-17 20:05:05 -03:00

884 lines
36 KiB
PHP

<?php
/**
* Plugin Name: HVAC Community Events
* Plugin URI: https://upskillhvac.com
* Description: Custom plugin for HVAC trainer event management system
* Version: 1.0.0
* Author: Upskill HVAC
* Author URI: https://upskillhvac.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: hvac-community-events
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
// Define plugin constants
define('HVAC_CE_VERSION', '1.0.0');
define('HVAC_CE_PLUGIN_FILE', __FILE__);
define('HVAC_CE_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('HVAC_CE_PLUGIN_URL', plugin_dir_url(__FILE__));
// Include the logger class early
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-logger.php';
/**
* Create required pages and roles upon plugin activation.
*/
function hvac_ce_create_required_pages() {
// Ensure the roles class is available
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-roles.php';
HVAC_Logger::info('Starting hierarchical page creation process', 'Activation');
// Initialize certificate security early to register rewrite rules before flush
if (file_exists(HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php')) {
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
$cert_security = HVAC_Certificate_Security::instance();
$cert_security->init_secure_download();
HVAC_Logger::info('Certificate security initialized during activation', 'Activation');
}
// Define hierarchical page structure
$parent_pages = [
'trainer' => [
'title' => 'Trainer',
'content' => '<!-- Trainer parent page - redirects to dashboard -->',
'children' => [
'dashboard' => [
'title' => 'Trainer Dashboard',
'content' => '<!-- wp:shortcode -->[hvac_dashboard]<!-- /wp:shortcode -->',
],
'registration' => [
'title' => 'Trainer Registration',
'content' => '<!-- wp:shortcode -->[hvac_trainer_registration]<!-- /wp:shortcode -->',
],
'my-profile' => [
'title' => 'Trainer Profile',
'content' => '<!-- wp:shortcode -->[hvac_trainer_profile]<!-- /wp:shortcode -->',
],
'email-attendees' => [
'title' => 'Email Attendees',
'content' => '<!-- wp:shortcode -->[hvac_email_attendees]<!-- /wp:shortcode -->',
],
'certificate-reports' => [
'title' => 'Certificate Reports',
'content' => '<!-- wp:shortcode -->[hvac_certificate_reports]<!-- /wp:shortcode -->',
],
'generate-certificates' => [
'title' => 'Generate Certificates',
'content' => '<!-- wp:shortcode -->[hvac_generate_certificates]<!-- /wp:shortcode -->',
],
'documentation' => [
'title' => 'Trainer Documentation',
'content' => '<!-- wp:shortcode -->[hvac_documentation]<!-- /wp:shortcode -->',
],
'attendee-profile' => [
'title' => 'Attendee Profile',
'content' => '<!-- wp:shortcode -->[hvac_attendee_profile]<!-- /wp:shortcode -->',
],
'communication-templates' => [
'title' => 'Communication Templates',
'content' => '<!-- wp:shortcode -->[hvac_communication_templates]<!-- /wp:shortcode -->',
],
'communication-schedules' => [
'title' => 'Communication Schedules',
'content' => '<!-- wp:shortcode -->[hvac_communication_schedules]<!-- /wp:shortcode -->',
],
'event' => [
'title' => 'Event',
'content' => '<!-- Event parent page -->',
'children' => [
'manage' => [
'title' => 'Manage Event',
'content' => '<!-- wp:shortcode -->[tribe_community_events view="submission_form"]<!-- /wp:shortcode -->',
],
'summary' => [
'title' => 'Event Summary',
'content' => '<!-- wp:shortcode -->[hvac_event_summary]<!-- /wp:shortcode -->',
],
]
]
]
],
'master-trainer' => [
'title' => 'Master Trainer',
'content' => '<!-- Master Trainer parent page - redirects to dashboard -->',
'children' => [
'dashboard' => [
'title' => 'Master Dashboard',
'content' => '<!-- wp:shortcode -->[hvac_master_dashboard]<!-- /wp:shortcode -->',
],
'certificate-fix' => [
'title' => 'Certificate System Diagnostics',
'content' => '<!-- wp:shortcode -->[hvac_certificate_fix]<!-- /wp:shortcode -->',
],
'google-sheets' => [
'title' => 'Google Sheets Integration',
'content' => '<!-- wp:shortcode -->[hvac_google_sheets]<!-- /wp:shortcode -->',
],
]
]
];
// Define root pages (flat structure)
$root_pages = [
'training-login' => [
'title' => 'Trainer Login',
'content' => '<!-- wp:shortcode -->[hvac_community_login]<!-- /wp:shortcode -->',
'template' => 'page-community-login.php',
],
];
$created_pages = [];
// Create root pages first
HVAC_Logger::info('Creating root pages...', 'Activation');
foreach ($root_pages as $slug => $page_data) {
$existing = get_page_by_path($slug);
if (!$existing) {
$page_args = [
'post_title' => $page_data['title'],
'post_name' => $slug,
'post_content' => $page_data['content'],
'post_status' => 'publish',
'post_type' => 'page',
'comment_status' => 'closed',
'ping_status' => 'closed',
];
if (!empty($page_data['template'])) {
$page_args['page_template'] = $page_data['template'];
}
$page_id = wp_insert_post($page_args);
if (!is_wp_error($page_id)) {
$created_pages[$slug] = $page_id;
HVAC_Logger::info("Created root page: {$page_data['title']} (/{$slug}/)", 'Activation');
} else {
HVAC_Logger::error("Failed to create root page: {$slug} - " . $page_id->get_error_message(), 'Activation');
}
} else {
HVAC_Logger::info("Root page exists: {$page_data['title']} (/{$slug}/)", 'Activation');
}
}
// Create hierarchical pages
HVAC_Logger::info('Creating hierarchical pages...', 'Activation');
foreach ($parent_pages as $parent_slug => $parent_data) {
// Create parent page
$existing_parent = get_page_by_path($parent_slug);
$parent_id = null;
if (!$existing_parent) {
$parent_args = [
'post_title' => $parent_data['title'],
'post_name' => $parent_slug,
'post_content' => $parent_data['content'],
'post_status' => 'publish',
'post_type' => 'page',
'comment_status' => 'closed',
'ping_status' => 'closed',
];
$parent_id = wp_insert_post($parent_args);
if (!is_wp_error($parent_id)) {
$created_pages[$parent_slug] = $parent_id;
HVAC_Logger::info("Created parent page: {$parent_data['title']} (/{$parent_slug}/)", 'Activation');
} else {
HVAC_Logger::error("Failed to create parent page: {$parent_slug} - " . $parent_id->get_error_message(), 'Activation');
continue;
}
} else {
$parent_id = $existing_parent->ID;
HVAC_Logger::info("Parent page exists: {$parent_data['title']} (/{$parent_slug}/)", 'Activation');
}
// Create child pages
if ($parent_id && isset($parent_data['children'])) {
foreach ($parent_data['children'] as $child_slug => $child_data) {
$full_path = $parent_slug . '/' . $child_slug;
$existing_child = get_page_by_path($full_path);
if (!$existing_child) {
$child_args = [
'post_title' => $child_data['title'],
'post_name' => $child_slug,
'post_content' => $child_data['content'],
'post_status' => 'publish',
'post_type' => 'page',
'post_parent' => $parent_id,
'comment_status' => 'closed',
'ping_status' => 'closed',
];
$child_id = wp_insert_post($child_args);
if (!is_wp_error($child_id)) {
$created_pages[$full_path] = $child_id;
HVAC_Logger::info("Created child page: {$child_data['title']} (/{$full_path}/)", 'Activation');
// Handle grandchildren (like event/manage, event/summary)
if (isset($child_data['children'])) {
foreach ($child_data['children'] as $grandchild_slug => $grandchild_data) {
$grandchild_path = $parent_slug . '/' . $child_slug . '/' . $grandchild_slug;
$existing_grandchild = get_page_by_path($grandchild_path);
if (!$existing_grandchild) {
$grandchild_args = [
'post_title' => $grandchild_data['title'],
'post_name' => $grandchild_slug,
'post_content' => $grandchild_data['content'],
'post_status' => 'publish',
'post_type' => 'page',
'post_parent' => $child_id,
'comment_status' => 'closed',
'ping_status' => 'closed',
];
$grandchild_id = wp_insert_post($grandchild_args);
if (!is_wp_error($grandchild_id)) {
$created_pages[$grandchild_path] = $grandchild_id;
HVAC_Logger::info("Created grandchild page: {$grandchild_data['title']} (/{$grandchild_path}/)", 'Activation');
} else {
HVAC_Logger::error("Failed to create grandchild page: {$grandchild_path} - " . $grandchild_id->get_error_message(), 'Activation');
}
} else {
HVAC_Logger::info("Grandchild page exists: {$grandchild_data['title']} (/{$grandchild_path}/)", 'Activation');
}
}
}
} else {
HVAC_Logger::error("Failed to create child page: {$full_path} - " . $child_id->get_error_message(), 'Activation');
}
} else {
HVAC_Logger::info("Child page exists: {$child_data['title']} (/{$full_path}/)", 'Activation');
}
}
}
}
// Store created pages in WordPress option
update_option('hvac_ce_created_pages', $created_pages);
HVAC_Logger::info('Page creation completed. Created ' . count($created_pages) . ' pages', 'Activation');
// Create the custom roles
$roles_manager = new HVAC_Roles();
// Create trainer role
$result = $roles_manager->create_trainer_role();
if ($result) {
HVAC_Logger::info('Successfully created hvac_trainer role.', 'Activation');
} else {
HVAC_Logger::error('Failed to create hvac_trainer role.', 'Activation');
}
// Create master trainer role
$master_result = $roles_manager->create_master_trainer_role();
if ($master_result) {
HVAC_Logger::info('Successfully created hvac_master_trainer role.', 'Activation');
} else {
HVAC_Logger::error('Failed to create hvac_master_trainer role.', 'Activation');
}
// Grant administrators access to dashboard to prevent redirect loops
$admin_access = $roles_manager->grant_admin_dashboard_access();
if ($admin_access) {
HVAC_Logger::info('Successfully granted admin dashboard access.', 'Activation');
} else {
HVAC_Logger::error('Failed to grant admin dashboard access.', 'Activation');
}
// Flush rewrite rules to ensure new URLs work
flush_rewrite_rules();
HVAC_Logger::info('Rewrite rules flushed', 'Activation');
HVAC_Logger::info('Completed hierarchical page creation and role setup process', 'Activation');
} // End hvac_ce_create_required_pages
register_activation_hook(__FILE__, 'hvac_ce_create_required_pages');
/**
* Handle backward compatibility redirects for old URLs.
*
* This function redirects old page URLs to their new hierarchical structure
* to maintain compatibility for existing bookmarks and external links.
*
* Uses the 'wp' hook to catch requests early, before 404 processing,
* so that legacy URLs work even if the pages don't exist in the database.
*/
function hvac_ce_handle_legacy_redirects() {
// Legacy URL to new URL mapping
$legacy_redirects = [
'community-login' => 'training-login',
'hvac-dashboard' => 'trainer/dashboard',
'master-dashboard' => 'master-trainer/dashboard',
'manage-event' => 'trainer/event/manage',
'trainer-profile' => 'trainer/my-profile',
'event-summary' => 'trainer/event/summary',
'email-attendees' => 'trainer/email-attendees',
'certificate-reports' => 'trainer/certificate-reports',
'generate-certificates' => 'trainer/generate-certificates',
'certificate-fix' => 'master-trainer/certificate-fix',
'hvac-documentation' => 'trainer/documentation',
'attendee-profile' => 'trainer/attendee-profile',
'google-sheets' => 'master-trainer/google-sheets',
'communication-templates' => 'trainer/communication-templates',
'communication-schedules' => 'trainer/communication-schedules',
'trainer-registration' => 'trainer/registration',
];
// Get the current request URI and parse it
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
$parsed_url = parse_url($request_uri);
$path = isset($parsed_url['path']) ? trim($parsed_url['path'], '/') : '';
// Extract the slug from the path (remove any subdirectory prefix)
$path_parts = explode('/', $path);
$current_slug = end($path_parts);
// Also check if the entire path matches a legacy redirect (for exact matches)
if (isset($legacy_redirects[$path])) {
$current_slug = $path;
}
// Check if current slug is a legacy URL that needs redirecting
if (isset($legacy_redirects[$current_slug])) {
$new_url = home_url('/' . $legacy_redirects[$current_slug] . '/');
// Preserve query parameters
if (!empty($_SERVER['QUERY_STRING'])) {
$new_url .= '?' . $_SERVER['QUERY_STRING'];
}
// Log the redirect for debugging
if (class_exists('HVAC_Logger')) {
HVAC_Logger::info("Legacy redirect: {$current_slug}{$legacy_redirects[$current_slug]}", 'Redirects');
}
// Perform 301 redirect
wp_redirect($new_url, 301);
exit;
}
}
add_action('wp', 'hvac_ce_handle_legacy_redirects', 1); // High priority to catch early
/**
* Additional early redirect handler for URLs that might not reach the 'wp' hook.
* This catches requests at the 'init' level for even earlier processing.
*/
function hvac_ce_handle_early_legacy_redirects() {
// Only run on frontend requests
if (is_admin()) {
return;
}
// Same mapping as above
$legacy_redirects = [
'community-login' => 'training-login',
'hvac-dashboard' => 'trainer/dashboard',
'master-dashboard' => 'master-trainer/dashboard',
'manage-event' => 'trainer/event/manage',
'trainer-profile' => 'trainer/my-profile',
'event-summary' => 'trainer/event/summary',
'email-attendees' => 'trainer/email-attendees',
'certificate-reports' => 'trainer/certificate-reports',
'generate-certificates' => 'trainer/generate-certificates',
'certificate-fix' => 'master-trainer/certificate-fix',
'hvac-documentation' => 'trainer/documentation',
'attendee-profile' => 'trainer/attendee-profile',
'google-sheets' => 'master-trainer/google-sheets',
'communication-templates' => 'trainer/communication-templates',
'communication-schedules' => 'trainer/communication-schedules',
'trainer-registration' => 'trainer/registration',
];
// Get the current request URI
$request_uri = $_SERVER['REQUEST_URI'] ?? '';
// Parse the URL to get the path
$parsed_url = parse_url($request_uri);
$path = isset($parsed_url['path']) ? trim($parsed_url['path'], '/') : '';
// Check for exact path matches first
foreach ($legacy_redirects as $legacy_slug => $new_path) {
// Check if the request path ends with the legacy slug
if ($path === $legacy_slug || (substr($path, -strlen('/' . $legacy_slug)) === '/' . $legacy_slug)) {
$new_url = home_url('/' . $new_path . '/');
// Preserve query parameters
if (!empty($_SERVER['QUERY_STRING'])) {
$new_url .= '?' . $_SERVER['QUERY_STRING'];
}
// Log the redirect for debugging
if (class_exists('HVAC_Logger')) {
HVAC_Logger::info("Early legacy redirect: {$legacy_slug}{$new_path}", 'Redirects');
}
// Perform 301 redirect
wp_redirect($new_url, 301);
exit;
}
}
}
add_action('init', 'hvac_ce_handle_early_legacy_redirects', 1); // Very high priority
/**
* Remove custom roles upon plugin deactivation.
*/
function hvac_ce_remove_roles() {
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-roles.php';
$roles_manager = new HVAC_Roles();
$roles_manager->remove_trainer_role();
$roles_manager->remove_master_trainer_role();
$roles_manager->revoke_admin_dashboard_access();
// Flush rewrite rules to clean up certificate download URLs
flush_rewrite_rules();
HVAC_Logger::info('Deactivation hook fired, removed hvac_trainer role and admin dashboard access, flushed rewrite rules.', 'Deactivation');
}
register_deactivation_hook(__FILE__, 'hvac_ce_remove_roles');
/**
* Enqueue common styles and scripts for HVAC Community Events pages
*/
function hvac_ce_enqueue_common_assets() {
// Add debug logging to see if function is being called
error_log('HVAC CSS Debug: enqueue_common_assets called on URL: ' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : 'unknown'));
// Early return if not on HVAC pages to prevent loading on home page
if (is_front_page() || is_home()) {
error_log('HVAC CSS Debug: Skipping - is front page or home');
return;
}
// Check if we're on an HVAC plugin page - include both hierarchical and flat page names
$hvac_pages = [
// Hierarchical page paths
'trainer/dashboard', 'trainer/registration', 'trainer/my-profile',
'trainer/event/manage', 'trainer/event/summary', 'trainer/email-attendees', 'trainer/certificate-reports',
'trainer/generate-certificates', 'master-trainer/certificate-fix', 'trainer/documentation', 'trainer/attendee-profile',
'master-trainer/dashboard', 'master-trainer/google-sheets', 'trainer/communication-templates', 'trainer/communication-schedules',
// Flat page names (legacy and backup)
'training-login', 'trainer-dashboard', 'trainer-registration', 'trainer-my-profile',
'trainer-event-manage', 'trainer-event-summary', 'trainer-email-attendees', 'trainer-certificate-reports',
'trainer-generate-certificates', 'master-trainer-certificate-fix', 'trainer-documentation', 'trainer-attendee-profile',
'master-trainer-dashboard', 'master-trainer-google-sheets', 'trainer-communication-templates', 'trainer-communication-schedules',
// Child page names only
'dashboard', 'registration', 'my-profile', 'manage', 'summary', 'email-attendees', 'certificate-reports',
'generate-certificates', 'certificate-fix', 'documentation', 'attendee-profile', 'google-sheets', 'communication-templates', 'communication-schedules'
];
// Check if we're on an HVAC page using multiple methods
$is_hvac_page = false;
// Method 1: Check by page slug/path
if (is_page($hvac_pages)) {
$is_hvac_page = true;
error_log('HVAC CSS Debug: Page detected via is_page() check');
}
// Method 2: Check by post content containing HVAC shortcodes
global $post;
if ($post && !$is_hvac_page) {
$content = $post->post_content;
$hvac_shortcodes = ['hvac_dashboard', 'hvac_master_dashboard', 'hvac_community_login', 'hvac_google_sheets', 'hvac_certificate_reports', 'hvac_generate_certificates'];
foreach ($hvac_shortcodes as $shortcode) {
if (strpos($content, $shortcode) !== false) {
$is_hvac_page = true;
error_log('HVAC CSS Debug: Page detected via shortcode: ' . $shortcode);
break;
}
}
}
// Method 3: Force enable for testing - check if URL contains known HVAC paths
if (!$is_hvac_page && isset($_SERVER['REQUEST_URI'])) {
$uri = $_SERVER['REQUEST_URI'];
if (strpos($uri, '/trainer/') !== false || strpos($uri, '/master-trainer/') !== false || strpos($uri, '/training-login/') !== false) {
$is_hvac_page = true;
error_log('HVAC CSS Debug: Page detected via URL path check: ' . $uri);
}
}
error_log('HVAC CSS Debug: Final is_hvac_page status: ' . ($is_hvac_page ? 'true' : 'false'));
error_log('HVAC CSS Debug: Current post: ' . ($post ? $post->post_name : 'no post'));
// Only proceed if we're on an HVAC page
if (!$is_hvac_page) {
error_log('HVAC CSS Debug: Skipping CSS enqueue - not an HVAC page');
return;
}
error_log('HVAC CSS Debug: Proceeding to enqueue CSS files');
// Enqueue the harmonized framework first - this provides the base styling
wp_enqueue_style(
'hvac-harmonized-framework',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-harmonized.css',
[], // No dependencies - this is the foundation
HVAC_CE_VERSION . '-v3.0.0'
);
// Enqueue the legacy common CSS file for backward compatibility
wp_enqueue_style(
'hvac-common-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-common.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION
);
// Enqueue animations CSS file (ONLY on HVAC pages)
wp_enqueue_style(
'hvac-animations',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-animations.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION
);
// Enqueue mobile navigation CSS file (ONLY on HVAC pages)
wp_enqueue_style(
'hvac-mobile-nav',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-mobile-nav.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION
);
// Enqueue print stylesheet
wp_enqueue_style(
'hvac-print-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-print.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION,
'print' // Print media only
);
// Enqueue the accessibility helper JS (ONLY on HVAC pages)
wp_enqueue_script(
'hvac-accessibility-js',
HVAC_CE_PLUGIN_URL . 'assets/js/hvac-accessibility.js',
[], // No dependencies
HVAC_CE_VERSION,
true // Load in footer
);
// Enqueue animations JS (ONLY on HVAC pages)
wp_enqueue_script(
'hvac-animations-js',
HVAC_CE_PLUGIN_URL . 'assets/js/hvac-animations.js',
[], // No dependencies
HVAC_CE_VERSION,
true // Load in footer
);
// Enqueue mobile navigation JS (ONLY on HVAC pages)
wp_enqueue_script(
'hvac-mobile-nav-js',
HVAC_CE_PLUGIN_URL . 'assets/js/hvac-mobile-nav.js',
[], // No dependencies
HVAC_CE_VERSION,
true // Load in footer
);
// Enqueue page-specific enhanced styles based on current page
if (is_page('trainer/dashboard')) {
wp_enqueue_style(
'hvac-dashboard-enhanced',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-dashboard-enhanced.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION . '-v3.0.0'
);
// Keep legacy for compatibility
wp_enqueue_style(
'hvac-dashboard-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-dashboard.css',
['hvac-dashboard-enhanced'], // Load after enhanced
HVAC_CE_VERSION
);
}
if (is_page('master-trainer/dashboard')) {
// Master dashboard uses same styling as regular dashboard
wp_enqueue_style(
'hvac-dashboard-enhanced',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-dashboard-enhanced.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION . '-v3.0.0'
);
wp_enqueue_style(
'hvac-dashboard-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-dashboard.css',
['hvac-dashboard-enhanced'], // Load after enhanced
HVAC_CE_VERSION
);
}
if (is_page('training-login')) {
wp_enqueue_style(
'hvac-community-login-enhanced',
HVAC_CE_PLUGIN_URL . 'assets/css/community-login-enhanced.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION . '-v3.0.0'
);
// Keep legacy for compatibility
wp_enqueue_style(
'hvac-community-login-style',
HVAC_CE_PLUGIN_URL . 'assets/css/community-login.css',
['hvac-community-login-enhanced'], // Load after enhanced
HVAC_CE_VERSION
);
}
if (is_page('trainer/registration')) {
wp_enqueue_style(
'hvac-registration-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-registration.css',
['hvac-common-style'], // Depends on common styles
HVAC_CE_VERSION
);
}
if (is_page('trainer/email-attendees')) {
wp_enqueue_style(
'hvac-email-attendees-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-email-attendees.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION
);
}
if (is_singular(Tribe__Events__Main::POSTTYPE) || is_page('trainer/event/summary')) {
wp_enqueue_style(
'hvac-event-summary-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-event-summary.css',
['hvac-common-style'], // Depends on common styles
HVAC_CE_VERSION
);
// Enqueue event summary JS for certificate actions
wp_enqueue_script(
'hvac-event-summary-js',
HVAC_CE_PLUGIN_URL . 'assets/js/hvac-event-summary.js',
['jquery'], // jQuery dependency
HVAC_CE_VERSION,
true // Load in footer
);
// Localize script with AJAX data
wp_localize_script('hvac-event-summary-js', 'hvacEventSummary', [
'ajaxUrl' => admin_url('admin-ajax.php'),
'certificateNonce' => wp_create_nonce('hvac_certificate_actions')
]);
}
// Enqueue certificate-related styles
if (is_page('trainer/certificate-reports') || is_page('trainer/generate-certificates') || is_page('master-trainer/certificate-fix')) {
wp_enqueue_style(
'hvac-certificates-enhanced',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-certificates-enhanced.css',
['hvac-harmonized-framework'], // Depends on harmonized framework
HVAC_CE_VERSION . '-v3.0.0'
);
// Keep legacy for compatibility
wp_enqueue_style(
'hvac-certificates-admin-style',
HVAC_CE_PLUGIN_URL . 'assets/css/hvac-certificates-admin.css',
['hvac-certificates-enhanced'], // Load after enhanced
HVAC_CE_VERSION
);
// Enqueue certificate JS
wp_enqueue_script(
'hvac-certificate-admin-js',
HVAC_CE_PLUGIN_URL . 'assets/js/hvac-certificate-admin.js',
['jquery', 'wp-color-picker'], // jQuery dependency
HVAC_CE_VERSION,
true // Load in footer
);
// Add WordPress color picker if needed
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('wp-color-picker');
// Localize script with AJAX data
wp_localize_script('hvac-certificate-admin-js', 'hvacCertificateData', [
'ajaxUrl' => admin_url('admin-ajax.php'),
'previewNonce' => wp_create_nonce('hvac_certificate_preview')
]);
}
}
add_action('wp_enqueue_scripts', 'hvac_ce_enqueue_common_assets');
/**
* Handle AJAX request for master dashboard events table
*/
function hvac_ce_handle_master_dashboard_events_ajax() {
// Verify nonce
if ( ! wp_verify_nonce( $_POST['nonce'], 'hvac_master_dashboard_nonce' ) ) {
wp_die( 'Security check failed' );
}
// Check permissions
if ( ! current_user_can( 'view_master_dashboard' ) && ! current_user_can( 'view_all_trainer_data' ) && ! current_user_can( 'manage_options' ) ) {
wp_die( 'Insufficient permissions' );
}
// Load master dashboard data class
if ( ! class_exists( 'HVAC_Master_Dashboard_Data' ) ) {
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-master-dashboard-data.php';
}
// Initialize master dashboard data handler
$master_data = new HVAC_Master_Dashboard_Data();
// Get table data with filters
$args = array(
'status' => sanitize_text_field( $_POST['status'] ?? 'all' ),
'search' => sanitize_text_field( $_POST['search'] ?? '' ),
'orderby' => sanitize_text_field( $_POST['orderby'] ?? 'date' ),
'order' => sanitize_text_field( $_POST['order'] ?? 'DESC' ),
'page' => absint( $_POST['page'] ?? 1 ),
'per_page' => absint( $_POST['per_page'] ?? 10 ),
'date_from' => sanitize_text_field( $_POST['date_from'] ?? '' ),
'date_to' => sanitize_text_field( $_POST['date_to'] ?? '' ),
'trainer_id' => absint( $_POST['trainer_id'] ?? 0 ),
);
$table_data = $master_data->get_events_table_data( $args );
wp_send_json_success( $table_data );
}
add_action( 'wp_ajax_hvac_master_dashboard_events', 'hvac_ce_handle_master_dashboard_events_ajax' );
add_action( 'wp_ajax_nopriv_hvac_master_dashboard_events', 'hvac_ce_handle_master_dashboard_events_ajax' );
/**
* Enqueue styles and scripts for admin dashboard
*/
function hvac_ce_enqueue_admin_assets($hook) {
// Only load on our dashboard page
if ($hook !== 'hvac-community-events_page_hvac-ce-dashboard') {
return;
}
// Enqueue dashboard CSS
wp_enqueue_style(
'hvac-admin-dashboard-style',
HVAC_CE_PLUGIN_URL . 'assets/css/admin-dashboard.css',
array('wp-admin'),
HVAC_CE_VERSION
);
// Enqueue dashboard JS
wp_enqueue_script(
'hvac-admin-dashboard-script',
HVAC_CE_PLUGIN_URL . 'assets/js/admin-dashboard.js',
array('jquery', 'wp-util'),
HVAC_CE_VERSION,
true
);
// Localize script with AJAX data
wp_localize_script('hvac-admin-dashboard-script', 'hvac_admin_dashboard', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('hvac_admin_nonce')
));
}
// Include the main plugin class
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-community-events.php';
// Include the help system
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-help-system.php';
// Initialize the plugin
function hvac_community_events_init() {
HVAC_Logger::info('Initializing HVAC Community Events plugin', 'Core');
return HVAC_Community_Events::instance();
}
add_action('plugins_loaded', 'hvac_community_events_init');
// Initialize certificate URL handler very early to catch URLs before 404
function hvac_init_certificate_url_handler() {
// Load the certificate URL handler class if not already loaded
if (!class_exists('HVAC_Certificate_URL_Handler')) {
$handler_file = HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-url-handler.php';
if (file_exists($handler_file)) {
require_once $handler_file;
}
}
// Initialize the handler if class exists
if (class_exists('HVAC_Certificate_URL_Handler')) {
HVAC_Certificate_URL_Handler::instance();
}
}
// Hook very early - before WordPress decides it's a 404
add_action('muplugins_loaded', 'hvac_init_certificate_url_handler', 1);
add_action('plugins_loaded', 'hvac_init_certificate_url_handler', 1);
/**
* Include custom template for single event summary page.
*
* @param string $template The path of the template to include.
* @return string The path of the template file.
*/
function hvac_ce_include_event_summary_template( $template ) {
// Check if it's a single event post type view
if ( is_singular( Tribe__Events__Main::POSTTYPE ) ) {
// Check if the custom template exists in the plugin's template directory
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/single-hvac-event-summary.php';
if ( file_exists( $custom_template ) ) {
// Return the path to the custom template
return $custom_template;
}
}
// Return the original template if not a single event or custom template doesn't exist
return $template;
}
/**
* Template routing for Order Summary Page.
*/
function hvac_ce_include_order_summary_template( $template ) {
if ( is_page( 'order-summary' ) && isset( $_GET['order_id'] ) && absint( $_GET['order_id'] ) > 0 ) {
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/single-hvac-order-summary.php';
if ( file_exists( $custom_template ) ) {
return $custom_template;
}
}
return $template;
}
// Removed - template handling is now in the main class
// add_filter( 'template_include', 'hvac_ce_include_event_summary_template', 99 );
/**
* Initialize attendee profile handler
*/
function hvac_init_attendee_profile() {
// Load the attendee profile class if not already loaded
if (!class_exists('HVAC_Attendee_Profile')) {
$profile_file = HVAC_CE_PLUGIN_DIR . 'includes/class-attendee-profile.php';
if (file_exists($profile_file)) {
require_once $profile_file;
}
}
// Initialize the handler if class exists
if (class_exists('HVAC_Attendee_Profile')) {
HVAC_Attendee_Profile::instance();
}
}
// Initialize on plugins_loaded
add_action('plugins_loaded', 'hvac_init_attendee_profile', 10);
// Include attendee profile helper functions
require_once HVAC_CE_PLUGIN_DIR . 'includes/helpers/attendee-profile-link.php';