upskill-event-manager/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/class-hvac-community-events.php
bengizmo 12e360b6e6 fix: Resolve Trainer Login page and link issues
- Fix shortcode registration for community login with correct namespace
- Create dedicated page template for community-login page
- Enable template_include filter to properly load custom page templates
- Fix early loading of Login_Handler class
- Update Trainer Login page title and template handling
- Ensure proper shortcode execution on the login page

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-05-19 17:54:43 -03:00

287 lines
No EOL
8 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
];
// 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');
}
}
// Load Zoho integration if in admin
if (is_admin()) {
$zoho_path = HVAC_CE_PLUGIN_DIR . 'includes/admin/class-zoho-admin.php';
if (file_exists($zoho_path)) {
require_once $zoho_path;
HVAC_Logger::info("Included Zoho admin interface", 'Core');
}
}
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'));
} // End init_hooks
/**
* 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 if in admin
if (is_admin()) {
$this->init_zoho_admin();
$this->init_admin_dashboard();
}
// Initialize forms
$this->init_forms();
// Initialize shortcodes
$this->init_shortcodes();
// 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
add_shortcode('hvac_community_login', array('\\HVAC_Community_Events\\Community\\Login_Handler', 'render_login_form'));
// 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'));
// Remove the event form shortcode as we're using TEC's shortcode instead
// add_shortcode('hvac_event_form', array('HVAC_Community_Event_Handler', 'render_event_form'));
// 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/dashboard/trainer-dashboard.php';
return ob_get_clean();
}
/**
* Render event summary content
*/
public function render_event_summary() {
// This can be used to display custom event summary content
return '<div class="hvac-event-summary">Event Summary Content Here</div>';
}
/**
* Include custom templates for plugin pages
*/
public function load_custom_templates($template) {
// Check for dashboard page
if (is_page('hvac-dashboard')) {
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/template-hvac-dashboard.php';
if (file_exists($custom_template)) {
return $custom_template;
}
}
// Check for community-login page
if (is_page('community-login')) {
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/page-community-login.php';
if (file_exists($custom_template)) {
return $custom_template;
}
}
// Check for my-events page
if (is_page('my-events')) {
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/page-my-events.php';
if (file_exists($custom_template)) {
return $custom_template;
}
}
// Check for single event view (temporary)
if ( is_singular( 'tribe_events' ) ) {
$custom_template = HVAC_CE_PLUGIN_DIR . 'templates/single-tribe_events.php';
if ( file_exists( $custom_template ) ) {
return $custom_template;
}
}
// Add future custom templates here
return $template;
} // End load_custom_templates
} // End class HVAC_Community_Events