define_constants(); $this->includes(); $this->init_hooks(); } /** * Define constants */ private function define_constants() { // Additional constants can be defined here } /** * Include required files */ private function includes() { require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-roles.php'; require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-registration.php'; require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-settings.php'; require_once HVAC_CE_PLUGIN_DIR . 'includes/community/class-login-handler.php'; // Add Login Handler require_once HVAC_CE_PLUGIN_DIR . 'includes/community/class-event-handler.php'; // Add Event Handler // Include dashboard data class if it's not autoloaded if ( ! class_exists('HVAC_Dashboard_Data') ) { require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-dashboard-data.php'; } } /** * 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 $roles = new HVAC_Roles(); $roles->remove_trainer_role(); // Additional deactivation tasks // ... } /** * Initialize plugin actions attached to 'init' hook */ public function init() { // Initialize handlers error_log('[HVAC DEBUG] HVAC_Community_Events::init() - Before new Login_Handler()'); // Updated Log new \HVAC_Community_Events\Community\Login_Handler(); error_log('[HVAC DEBUG] HVAC_Community_Events::init() - Before new HVAC_Registration()'); // Updated Log new HVAC_Registration(); // Instantiate Registration class to register shortcode error_log('[HVAC DEBUG] HVAC_Community_Events::init() - After new HVAC_Registration()'); // Updated Log // Prevent trainers from accessing wp-admin add_action('admin_init', array($this, 'redirect_trainers_from_admin')); } /** * Redirect HVAC trainers from admin area to frontend dashboard */ public function redirect_trainers_from_admin() { if (defined('DOING_AJAX') && DOING_AJAX) { return; } // Check if user is trying to access wp-admin and has trainer role but not admin caps if ( is_admin() && ! current_user_can('manage_options') && current_user_can('view_hvac_dashboard') ) { wp_redirect(home_url('/hvac-dashboard/')); // Corrected slug exit; } } /** * Load custom templates for plugin pages. * * @param string $template The path of the template to include. * @return string The path of the template to include. */ public function load_custom_templates( $template ) { // Check if we are on the HVAC Dashboard page if ( is_page( 'hvac-dashboard' ) ) { $new_template = HVAC_CE_PLUGIN_DIR . 'templates/template-hvac-dashboard.php'; if ( file_exists( $new_template ) ) { return $new_template; } } // Add checks for other custom pages here if needed return $template; } } // End class HVAC_Community_Events