- Created new HVAC_Certificate_URL_Handler class that intercepts certificate URLs directly - Hooks into multiple early WordPress actions (plugins_loaded, init, parse_request) - Bypasses WordPress rewrite rules for more reliable certificate URL handling - Added early initialization in main plugin file before WordPress routing - Includes comprehensive test tool for certificate URL verification This should resolve certificate viewing 404 errors by handling URLs before WordPress routing. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
807 lines
No EOL
27 KiB
PHP
807 lines
No EOL
27 KiB
PHP
<?php
|
|
/**
|
|
* Main plugin class for HVAC Community Events
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class HVAC_Community_Events {
|
|
/**
|
|
* The single instance of the class
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Main instance
|
|
*/
|
|
public static function instance() {
|
|
if (is_null(self::$instance)) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
HVAC_Logger::info('HVAC_Community_Events constructor started', 'Core');
|
|
$this->define_constants();
|
|
HVAC_Logger::info('Constants defined', 'Core');
|
|
$this->includes();
|
|
HVAC_Logger::info('Includes completed', 'Core');
|
|
$this->init_hooks();
|
|
HVAC_Logger::info('Hooks initialized', 'Core');
|
|
}
|
|
|
|
/**
|
|
* Define constants
|
|
*/
|
|
private function define_constants() {
|
|
// Additional constants can be defined here
|
|
}
|
|
|
|
/**
|
|
* Include required files
|
|
*/
|
|
private function includes() {
|
|
HVAC_Logger::info('Loading required files', 'Core');
|
|
$files_to_include = [
|
|
'class-hvac-roles.php',
|
|
'class-hvac-registration.php',
|
|
'class-hvac-settings.php',
|
|
'community/class-login-handler.php',
|
|
'community/class-event-handler.php',
|
|
'class-hvac-dashboard-data.php',
|
|
'class-event-form-handler.php', // Add our form handler
|
|
'class-event-author-fixer.php', // Fix event author assignment
|
|
'class-hvac-dashboard.php', // New dashboard handler
|
|
'certificates/class-certificate-installer.php', // Certificate database installer
|
|
'certificates/class-certificate-manager.php', // Certificate management
|
|
'certificates/class-certificate-generator.php', // Certificate generation
|
|
'certificates/class-certificate-settings.php', // Certificate settings
|
|
'certificates/class-certificate-template.php', // Certificate template
|
|
'certificates/class-certificate-security.php', // Certificate security
|
|
'certificates/class-certificate-url-handler.php', // Certificate URL handler
|
|
'certificates/class-certificate-ajax-handler.php', // Certificate AJAX handling
|
|
'certificates/class-certificate-fix.php', // Certificate diagnostic/fix tool
|
|
'community/class-email-debug.php', // Email debugging tools
|
|
'certificates/test-rewrite-rules.php' // Rewrite rules testing (temporary)
|
|
];
|
|
// Make sure Login_Handler is loaded first for shortcode registration
|
|
$login_handler_path = HVAC_CE_PLUGIN_DIR . 'includes/community/class-login-handler.php';
|
|
if (file_exists($login_handler_path)) {
|
|
require_once $login_handler_path;
|
|
HVAC_Logger::info("Included file: community/class-login-handler.php", 'Core');
|
|
}
|
|
|
|
foreach ($files_to_include as $file) {
|
|
// Skip Login_Handler as we've already loaded it
|
|
if ($file === 'community/class-login-handler.php') {
|
|
continue;
|
|
}
|
|
|
|
$path = HVAC_CE_PLUGIN_DIR . 'includes/' . $file;
|
|
if (file_exists($path)) {
|
|
require_once $path;
|
|
HVAC_Logger::info("Included file: {$file}", 'Core');
|
|
} else {
|
|
HVAC_Logger::error("Failed to include file: {$file} - File not found", 'Core');
|
|
}
|
|
}
|
|
|
|
// Note: Zoho admin interface will be loaded in init_zoho_admin() method during hooks initialization
|
|
|
|
HVAC_Logger::info('All required files loaded', 'Core');
|
|
}
|
|
|
|
/**
|
|
* Initialize hooks
|
|
*/
|
|
private function init_hooks() {
|
|
// Register activation/deactivation hooks
|
|
// Note: These hooks are typically registered outside the class instance context
|
|
// register_activation_hook(__FILE__, array($this, 'activate')); // This won't work correctly here
|
|
// register_deactivation_hook(__FILE__, array($this, 'deactivate')); // This won't work correctly here
|
|
|
|
// Initialize other hooks
|
|
add_action('init', array($this, 'init'));
|
|
|
|
// Template loading for custom pages
|
|
add_filter('template_include', array($this, 'load_custom_templates'));
|
|
|
|
// Add authentication check for event summary page
|
|
add_action('template_redirect', array($this, 'check_event_summary_auth'));
|
|
|
|
// Add authentication check for email attendees page
|
|
add_action('template_redirect', array($this, 'check_email_attendees_auth'));
|
|
|
|
// Add authentication check for certificate pages
|
|
add_action('template_redirect', array($this, 'check_certificate_pages_auth'));
|
|
} // End init_hooks
|
|
|
|
/**
|
|
* Check authentication for event summary page
|
|
*/
|
|
public function check_event_summary_auth() {
|
|
// Check if we're on the event-summary page
|
|
if (is_page('event-summary') && !is_user_logged_in()) {
|
|
// Redirect to login page
|
|
wp_redirect(home_url('/community-login/?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])));
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check authentication for email attendees page
|
|
*/
|
|
public function check_email_attendees_auth() {
|
|
// Check if we're on the email-attendees page
|
|
if (is_page('email-attendees') && !is_user_logged_in()) {
|
|
// Redirect to login page
|
|
wp_redirect(home_url('/community-login/?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])));
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Check authentication for certificate pages
|
|
*/
|
|
public function check_certificate_pages_auth() {
|
|
// Check if we're on certificate-related pages
|
|
if ((is_page('certificate-reports') || is_page('generate-certificates')) && !is_user_logged_in()) {
|
|
// Redirect to login page
|
|
wp_redirect(home_url('/community-login/?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])));
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Plugin activation (Should be called statically or from the main plugin file context)
|
|
*/
|
|
public static function activate() {
|
|
// Activation code here (e.g., page creation, role creation)
|
|
// Note: This method might need to be moved or called differently
|
|
}
|
|
|
|
/**
|
|
* Plugin deactivation (Should be called statically or from the main plugin file context)
|
|
*/
|
|
public static function deactivate() {
|
|
// Remove the hvac_trainer role
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-roles.php'; // Ensure class is available
|
|
HVAC_Roles::remove_hvac_trainer_role();
|
|
HVAC_Logger::info('Deactivation completed: HVAC trainer role removed.', 'Core');
|
|
}
|
|
|
|
/**
|
|
* Initialize function (hooked on 'init')
|
|
*/
|
|
public function init() {
|
|
// Initialize roles
|
|
$this->init_roles();
|
|
|
|
// Initialize settings (admin menu)
|
|
$this->init_settings();
|
|
|
|
// Initialize Zoho admin always (needed for AJAX)
|
|
$this->init_zoho_admin();
|
|
|
|
// Initialize admin dashboard if in admin or handling AJAX
|
|
if (is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
|
|
$this->init_admin_dashboard();
|
|
}
|
|
|
|
// Initialize forms
|
|
$this->init_forms();
|
|
|
|
// Initialize shortcodes
|
|
$this->init_shortcodes();
|
|
|
|
// Initialize certificate AJAX handler
|
|
if (class_exists('HVAC_Certificate_AJAX_Handler')) {
|
|
HVAC_Certificate_AJAX_Handler::instance();
|
|
}
|
|
|
|
// Initialize certificate security
|
|
if (class_exists('HVAC_Certificate_Security')) {
|
|
HVAC_Certificate_Security::instance();
|
|
}
|
|
|
|
// Initialize certificate URL handler
|
|
if (class_exists('HVAC_Certificate_URL_Handler')) {
|
|
HVAC_Certificate_URL_Handler::instance();
|
|
}
|
|
|
|
// Add manual flush rewrite rules for admins (debugging)
|
|
if (is_admin() && current_user_can('manage_options') && isset($_GET['hvac_flush_rewrite']) && $_GET['hvac_flush_rewrite'] === '1') {
|
|
flush_rewrite_rules();
|
|
wp_die('Rewrite rules flushed. <a href="' . admin_url() . '">Return to admin</a>');
|
|
}
|
|
|
|
// Initialize event form handler
|
|
if (class_exists('HVAC_Community_Events\Event_Form_Handler')) {
|
|
new \HVAC_Community_Events\Event_Form_Handler();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize roles
|
|
*/
|
|
private function init_roles() {
|
|
$roles = new HVAC_Roles();
|
|
// Note: Role creation is handled in the activate method or the class constructor
|
|
}
|
|
|
|
/**
|
|
* Initialize settings
|
|
*/
|
|
private function init_settings() {
|
|
new HVAC_Settings();
|
|
}
|
|
|
|
/**
|
|
* Initialize Zoho admin
|
|
*/
|
|
private function init_zoho_admin() {
|
|
if (file_exists(HVAC_CE_PLUGIN_DIR . 'includes/admin/class-zoho-admin.php')) {
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/admin/class-zoho-admin.php';
|
|
new HVAC_Zoho_Admin();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize admin dashboard
|
|
*/
|
|
private function init_admin_dashboard() {
|
|
if (file_exists(HVAC_CE_PLUGIN_DIR . 'includes/admin/class-admin-dashboard.php')) {
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/admin/class-admin-dashboard.php';
|
|
new HVAC_Admin_Dashboard();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize forms
|
|
*/
|
|
private function init_forms() {
|
|
$registration = new HVAC_Registration();
|
|
// Note: Form registration is handled in the class constructor
|
|
}
|
|
|
|
/**
|
|
* Initialize shortcodes
|
|
*/
|
|
private function init_shortcodes() {
|
|
// Registration form shortcode
|
|
add_shortcode('hvac_trainer_registration', array('HVAC_Registration', 'render_registration_form'));
|
|
|
|
// Community login shortcode - initialize Login_Handler to register the shortcode
|
|
new \HVAC_Community_Events\Community\Login_Handler();
|
|
|
|
// Dashboard shortcode
|
|
add_shortcode('hvac_dashboard', array($this, 'render_dashboard'));
|
|
|
|
// Add the event summary shortcode
|
|
add_shortcode('hvac_event_summary', array($this, 'render_event_summary'));
|
|
|
|
// Add trainer profile shortcode
|
|
add_shortcode('hvac_trainer_profile', array($this, 'render_trainer_profile'));
|
|
|
|
// Add edit profile shortcode
|
|
add_shortcode('hvac_edit_profile', array('HVAC_Registration', 'render_edit_profile_form'));
|
|
|
|
// Add email attendees shortcode
|
|
add_shortcode('hvac_email_attendees', array($this, 'render_email_attendees'));
|
|
|
|
// Add certificate reports shortcode
|
|
add_shortcode('hvac_certificate_reports', array($this, 'render_certificate_reports'));
|
|
|
|
// Add generate certificates shortcode
|
|
add_shortcode('hvac_generate_certificates', array($this, 'render_generate_certificates'));
|
|
|
|
// Add certificate fix shortcode (admin only)
|
|
add_shortcode('hvac_certificate_fix', array($this, 'render_certificate_fix'));
|
|
|
|
// Add community events shortcode as fallback if TEC CE is not available
|
|
add_shortcode('tribe_community_events', array($this, 'render_tribe_community_events'));
|
|
|
|
// Add future shortcodes here
|
|
}
|
|
|
|
/**
|
|
* Render dashboard content
|
|
*/
|
|
public function render_dashboard() {
|
|
if (!is_user_logged_in()) {
|
|
return '<p>Please log in to view the dashboard.</p>';
|
|
}
|
|
|
|
// Include the dashboard template
|
|
ob_start();
|
|
include HVAC_CE_PLUGIN_DIR . 'templates/template-hvac-dashboard.php';
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Render event summary content
|
|
*/
|
|
public function render_event_summary() {
|
|
// Check if user is logged in
|
|
if (!is_user_logged_in()) {
|
|
return '<p>Please log in to view the event summary.</p>';
|
|
}
|
|
|
|
// Get event ID from URL parameter
|
|
$event_id = isset($_GET['event_id']) ? absint($_GET['event_id']) : 0;
|
|
|
|
if ($event_id <= 0) {
|
|
return '<div class="hvac-error">No event ID provided. Please access this page from your dashboard.</div>';
|
|
}
|
|
|
|
// Check if the event exists and user has permission to view it
|
|
$event = get_post($event_id);
|
|
if (!$event || get_post_type($event) !== Tribe__Events__Main::POSTTYPE) {
|
|
return '<div class="hvac-error">Event not found or invalid.</div>';
|
|
}
|
|
|
|
// Check if the current user has permission to view this event
|
|
// For now, we'll check if they're the post author or have edit_posts capability
|
|
if ($event->post_author != get_current_user_id() && !current_user_can('edit_posts')) {
|
|
return '<div class="hvac-error">You do not have permission to view this event summary.</div>';
|
|
}
|
|
|
|
// Include the event summary template
|
|
ob_start();
|
|
include HVAC_CE_PLUGIN_DIR . 'templates/event-summary/template-event-summary.php';
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Render trainer profile content
|
|
*/
|
|
public function render_trainer_profile() {
|
|
if (!is_user_logged_in()) {
|
|
return '<p>Please log in to view your profile.</p>';
|
|
}
|
|
|
|
// Include the trainer profile template
|
|
ob_start();
|
|
include HVAC_CE_PLUGIN_DIR . 'templates/template-trainer-profile.php';
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Render email attendees content
|
|
*/
|
|
public function render_email_attendees() {
|
|
// Check if user is logged in
|
|
if (!is_user_logged_in()) {
|
|
return '<p>Please log in to email event attendees.</p>';
|
|
}
|
|
|
|
// Get event ID from URL parameter
|
|
$event_id = isset($_GET['event_id']) ? absint($_GET['event_id']) : 0;
|
|
|
|
if ($event_id <= 0) {
|
|
return '<div class="hvac-error">No event ID provided. Please access this page from your dashboard or event summary page.</div>';
|
|
}
|
|
|
|
// Check if the event exists and user has permission to view it
|
|
$event = get_post($event_id);
|
|
if (!$event || get_post_type($event) !== Tribe__Events__Main::POSTTYPE) {
|
|
return '<div class="hvac-error">Event not found or invalid.</div>';
|
|
}
|
|
|
|
// Check if the current user has permission to view this event
|
|
// For now, we'll check if they're the post author or have edit_posts capability
|
|
if ($event->post_author != get_current_user_id() && !current_user_can('edit_posts')) {
|
|
return '<div class="hvac-error">You do not have permission to email attendees for this event.</div>';
|
|
}
|
|
|
|
// Include the email attendees template
|
|
ob_start();
|
|
include HVAC_CE_PLUGIN_DIR . 'templates/email-attendees/template-email-attendees.php';
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Validate template file for common syntax errors
|
|
* @param string $file_path Path to the template file
|
|
* @return bool|string True if valid, error message otherwise
|
|
*/
|
|
private function validate_template_file($file_path) {
|
|
// Check if the file exists
|
|
if (!file_exists($file_path)) {
|
|
return "Template file does not exist: {$file_path}";
|
|
}
|
|
|
|
// Get file contents
|
|
$content = file_get_contents($file_path);
|
|
|
|
// Check for common syntax errors with escaped operators
|
|
$common_errors = [
|
|
'\\!==', // Escaped !==
|
|
'\\!=' , // Escaped !=
|
|
'\\!' , // Escaped !
|
|
'\\=' , // Escaped =
|
|
'\\>' , // Escaped >
|
|
'\\<' , // Escaped <
|
|
];
|
|
|
|
foreach ($common_errors as $error) {
|
|
if (strpos($content, $error) !== false) {
|
|
// Find the line number
|
|
$lines = explode("\n", $content);
|
|
$line_number = 0;
|
|
foreach ($lines as $i => $line) {
|
|
if (strpos($line, $error) !== false) {
|
|
$line_number = $i + 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Log the error for admin
|
|
$filename = basename($file_path);
|
|
HVAC_Logger::error("Syntax error detected in {$filename} line {$line_number}: Improper escape sequence {$error}", 'Core');
|
|
|
|
return "Template file contains syntax errors: {$filename} line {$line_number}. Please contact the administrator.";
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Render certificate reports content
|
|
*/
|
|
public function render_certificate_reports() {
|
|
// Check if user is logged in
|
|
if (!is_user_logged_in()) {
|
|
return '<p>Please log in to view certificate reports.</p>';
|
|
}
|
|
|
|
// Check if the current user has permission to view certificate reports
|
|
// For now, we'll check if they're a trainer or have edit_posts capability
|
|
if (!current_user_can('hvac_trainer') && !current_user_can('edit_posts')) {
|
|
return '<div class="hvac-error">You do not have permission to view certificate reports.</div>';
|
|
}
|
|
|
|
// Make sure certificate manager is loaded
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
|
|
|
// Make sure certificate security is loaded
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
|
|
|
|
// Validate the template file before including
|
|
$template_path = HVAC_CE_PLUGIN_DIR . 'templates/certificates/template-certificate-reports.php';
|
|
$validation = $this->validate_template_file($template_path);
|
|
if ($validation !== true) {
|
|
return '<div class="hvac-error">' . esc_html($validation) . '</div>';
|
|
}
|
|
|
|
// Include the certificate reports template with error handling
|
|
try {
|
|
ob_start();
|
|
include $template_path;
|
|
return ob_get_clean();
|
|
} catch (Exception $e) {
|
|
return '<div class="hvac-error">Error loading certificate reports: ' . esc_html($e->getMessage()) . '</div>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Render generate certificates content
|
|
*/
|
|
public function render_generate_certificates() {
|
|
// Check if user is logged in
|
|
if (!is_user_logged_in()) {
|
|
return '<p>Please log in to generate certificates.</p>';
|
|
}
|
|
|
|
// Get event ID from URL parameter if available
|
|
$event_id = isset($_GET['event_id']) ? absint($_GET['event_id']) : 0;
|
|
|
|
// Check if the event exists and user has permission to view it when event_id is provided
|
|
if ($event_id > 0) {
|
|
$event = get_post($event_id);
|
|
if (!$event || get_post_type($event) !== Tribe__Events__Main::POSTTYPE) {
|
|
return '<div class="hvac-error">Event not found or invalid.</div>';
|
|
}
|
|
|
|
// Check if the current user has permission to view this event
|
|
if ($event->post_author != get_current_user_id() && !current_user_can('edit_posts')) {
|
|
return '<div class="hvac-error">You do not have permission to generate certificates for this event.</div>';
|
|
}
|
|
} else {
|
|
// If no event ID is provided, check general permissions
|
|
if (!current_user_can('hvac_trainer') && !current_user_can('edit_posts')) {
|
|
return '<div class="hvac-error">You do not have permission to generate certificates.</div>';
|
|
}
|
|
}
|
|
|
|
// Make sure certificate manager is loaded
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-manager.php';
|
|
|
|
// Make sure certificate security is loaded
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-security.php';
|
|
|
|
// Make sure certificate generator is loaded
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/certificates/class-certificate-generator.php';
|
|
|
|
// Validate the template file before including
|
|
$template_path = HVAC_CE_PLUGIN_DIR . 'templates/certificates/template-generate-certificates.php';
|
|
$validation = $this->validate_template_file($template_path);
|
|
if ($validation !== true) {
|
|
return '<div class="hvac-error">' . esc_html($validation) . '</div>';
|
|
}
|
|
|
|
// Include the generate certificates template with error handling
|
|
try {
|
|
ob_start();
|
|
include $template_path;
|
|
return ob_get_clean();
|
|
} catch (Exception $e) {
|
|
return '<div class="hvac-error">Error loading certificate generation: ' . esc_html($e->getMessage()) . '</div>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Include custom templates for plugin pages
|
|
*/
|
|
public function load_custom_templates($template) {
|
|
$custom_template = null;
|
|
|
|
// Check for dashboard page
|
|
if (is_page('hvac-dashboard')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/template-hvac-dashboard.php';
|
|
}
|
|
|
|
// Check for community-login page
|
|
if (is_page('community-login')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/page-community-login.php';
|
|
}
|
|
|
|
|
|
// Check for trainer-profile page
|
|
if (is_page('trainer-profile')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/template-trainer-profile.php';
|
|
}
|
|
|
|
// Check for event-summary page
|
|
if (is_page('event-summary')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/template-event-summary.php';
|
|
}
|
|
|
|
// Check for email-attendees page
|
|
if (is_page('email-attendees')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/email-attendees/template-email-attendees.php';
|
|
}
|
|
|
|
// Check for certificate-reports page
|
|
if (is_page('certificate-reports')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/certificates/template-certificate-reports.php';
|
|
}
|
|
|
|
// Check for generate-certificates page
|
|
if (is_page('generate-certificates')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/certificates/template-generate-certificates.php';
|
|
}
|
|
|
|
// Check for edit-profile page
|
|
if (is_page('edit-profile')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/template-edit-profile.php';
|
|
}
|
|
|
|
// Check for single event view (temporary)
|
|
if (is_singular('tribe_events')) {
|
|
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/single-tribe_events.php';
|
|
}
|
|
|
|
// Process the custom template if one was found
|
|
if ($custom_template !== null) {
|
|
// Check if file exists
|
|
if (file_exists($custom_template)) {
|
|
// Validate certificate templates for syntax errors
|
|
if (strpos($custom_template, 'certificates/') !== false) {
|
|
$validation = $this->validate_template_file($custom_template);
|
|
if ($validation !== true) {
|
|
// Log error and show friendly message
|
|
HVAC_Logger::error("Template validation failed in load_custom_templates: {$validation}", 'Core');
|
|
|
|
// Display error or fallback template
|
|
add_action('wp_head', function() use ($validation) {
|
|
echo '<div class="hvac-error">There was a problem loading this page. ' .
|
|
'The administrator has been notified. Please try again later.</div>';
|
|
});
|
|
|
|
// Either fall back to the standard WP template or use a simple error template
|
|
return $template;
|
|
}
|
|
}
|
|
|
|
// Template exists and passes validation
|
|
return $custom_template;
|
|
}
|
|
}
|
|
|
|
return $template;
|
|
} // End load_custom_templates
|
|
|
|
/**
|
|
* Render tribe community events shortcode
|
|
*/
|
|
public function render_tribe_community_events($atts) {
|
|
// Parse shortcode attributes
|
|
$atts = shortcode_atts(array(
|
|
'view' => 'submission_form'
|
|
), $atts);
|
|
|
|
// Check if user is logged in
|
|
if (!is_user_logged_in()) {
|
|
return '<p>Please log in to access this feature.</p>';
|
|
}
|
|
|
|
// Check if user has permission
|
|
if (!current_user_can('hvac_trainer') && !current_user_can('edit_posts')) {
|
|
return '<div class="hvac-error">You do not have permission to access this feature.</div>';
|
|
}
|
|
|
|
// Check if TEC Community Events is active and working
|
|
if (class_exists('Tribe__Events__Community__Main')) {
|
|
// Check if the TEC shortcode handler exists
|
|
global $shortcode_tags;
|
|
$tec_handler = null;
|
|
|
|
// Look for TEC's original handler
|
|
if (isset($shortcode_tags['tribe_community_events'])) {
|
|
$current_handler = $shortcode_tags['tribe_community_events'];
|
|
|
|
// If it's our handler, temporarily remove it to find TEC's
|
|
if ($current_handler === array($this, 'render_tribe_community_events')) {
|
|
remove_shortcode('tribe_community_events');
|
|
|
|
// Try to get TEC's handler by calling their main class
|
|
if (class_exists('Tribe__Events__Community__Shortcodes')) {
|
|
$tec_shortcodes = new Tribe__Events__Community__Shortcodes();
|
|
if (method_exists($tec_shortcodes, 'tribe_community_events')) {
|
|
$tec_handler = array($tec_shortcodes, 'tribe_community_events');
|
|
}
|
|
}
|
|
|
|
// If we found TEC's handler, use it
|
|
if ($tec_handler && is_callable($tec_handler)) {
|
|
$output = call_user_func($tec_handler, $atts);
|
|
|
|
// Re-add our handler for next time
|
|
add_shortcode('tribe_community_events', array($this, 'render_tribe_community_events'));
|
|
|
|
if (!empty($output) && !is_wp_error($output)) {
|
|
return $output;
|
|
}
|
|
}
|
|
|
|
// Re-add our handler if TEC didn't work
|
|
add_shortcode('tribe_community_events', array($this, 'render_tribe_community_events'));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Handle different views
|
|
switch ($atts['view']) {
|
|
case 'submission_form':
|
|
return $this->render_event_submission_form();
|
|
default:
|
|
return '<div class="hvac-error">Unknown view: ' . esc_html($atts['view']) . '</div>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Render event submission form
|
|
*/
|
|
private function render_event_submission_form() {
|
|
ob_start();
|
|
?>
|
|
<div class="hvac-event-form-container">
|
|
<!-- Navigation Header -->
|
|
<div class="hvac-dashboard-header">
|
|
<h1 class="entry-title">Create New Training Event</h1>
|
|
<div class="hvac-dashboard-nav">
|
|
<a href="<?php echo esc_url( home_url( '/hvac-dashboard/' ) ); ?>" class="ast-button ast-button-secondary">Dashboard</a>
|
|
<a href="<?php echo esc_url( home_url( '/certificate-reports/' ) ); ?>" class="ast-button ast-button-secondary">Certificate Reports</a>
|
|
<a href="<?php echo esc_url( home_url( '/generate-certificates/' ) ); ?>" class="ast-button ast-button-primary">Generate Certificates</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hvac-event-form-header">
|
|
<?php if (!class_exists('Tribe__Events__Community__Main')) : ?>
|
|
<div class="hvac-notice hvac-notice-warning">
|
|
<p><strong>Notice:</strong> The Events Calendar Community Events plugin is not active. Using basic event creation form.</p>
|
|
<p>For full event management features, please contact your administrator to activate The Events Calendar Community Events plugin.</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<p>Fill out the form below to create a new training event. All events are reviewed before being published.</p>
|
|
</div>
|
|
|
|
<div class="hvac-event-form-instructions">
|
|
<h3>Instructions</h3>
|
|
<ul>
|
|
<li>Provide a clear, descriptive title for your training event</li>
|
|
<li>Include detailed description of what attendees will learn</li>
|
|
<li>Set appropriate pricing for your target audience</li>
|
|
<li>Ensure venue information is accurate and complete</li>
|
|
<li>Events will be reviewed within 1-2 business days</li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
<!-- Fallback form for basic event creation -->
|
|
<form id="hvac-basic-event-form" method="post" action="">
|
|
<?php wp_nonce_field('hvac_create_event', 'hvac_event_nonce'); ?>
|
|
|
|
<div class="hvac-form-field">
|
|
<label for="event_title">Event Title *</label>
|
|
<input type="text" id="event_title" name="event_title" required>
|
|
</div>
|
|
|
|
<div class="hvac-form-field">
|
|
<label for="event_description">Event Description *</label>
|
|
<textarea id="event_description" name="event_description" rows="5" required></textarea>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<div class="hvac-form-field">
|
|
<label for="event_start_date">Start Date *</label>
|
|
<input type="date" id="event_start_date" name="event_start_date" required>
|
|
</div>
|
|
<div class="hvac-form-field">
|
|
<label for="event_start_time">Start Time *</label>
|
|
<input type="time" id="event_start_time" name="event_start_time" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hvac-form-row">
|
|
<div class="hvac-form-field">
|
|
<label for="event_end_date">End Date *</label>
|
|
<input type="date" id="event_end_date" name="event_end_date" required>
|
|
</div>
|
|
<div class="hvac-form-field">
|
|
<label for="event_end_time">End Time *</label>
|
|
<input type="time" id="event_end_time" name="event_end_time" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="hvac-form-field">
|
|
<label for="event_venue">Venue Name</label>
|
|
<input type="text" id="event_venue" name="event_venue">
|
|
</div>
|
|
|
|
<div class="hvac-form-field">
|
|
<label for="event_address">Venue Address</label>
|
|
<textarea id="event_address" name="event_address" rows="3"></textarea>
|
|
</div>
|
|
|
|
<div class="hvac-form-field">
|
|
<label for="event_price">Ticket Price ($)</label>
|
|
<input type="number" id="event_price" name="event_price" min="0" step="0.01">
|
|
</div>
|
|
|
|
<div class="hvac-form-field">
|
|
<label for="event_capacity">Maximum Capacity</label>
|
|
<input type="number" id="event_capacity" name="event_capacity" min="1">
|
|
</div>
|
|
|
|
<div class="hvac-form-actions">
|
|
<button type="submit" class="button button-primary">Submit Event for Review</button>
|
|
<a href="<?php echo home_url('/hvac-dashboard/'); ?>" class="button button-secondary">Return to Dashboard</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
return ob_get_clean();
|
|
}
|
|
|
|
|
|
|
|
} // End class HVAC_Community_Events
|