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' ]; foreach ($files_to_include as $file) { $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'); } } 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 $roles = new HVAC_Roles(); $roles->remove_trainer_role(); // Additional deactivation tasks // ... } /** * Initialize plugin actions attached to 'init' hook */ public function init() { HVAC_Logger::info('Init method started', 'Core'); // Initialize handlers new \HVAC_Community_Events\Community\Login_Handler(); HVAC_Logger::info('Login_Handler initialized', 'Core'); new HVAC_Registration(); HVAC_Logger::info('HVAC_Registration initialized', 'Core'); HVAC_Logger::info('Init method completed', 'Core'); // 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