- Add HVAC_Test_User_Factory class with: * User creation with specific roles * Multiple role support * Persona management system * Account cleanup integration - Create comprehensive test suite in HVAC_Test_User_Factory_Test.php - Update testing improvement plan documentation - Add implementation decisions to project memory bank - Restructure .gitignore with: * Whitelist approach for better file management * Explicit backup exclusions * Specific bin directory inclusions Part of the Account Management component from the testing framework improvement plan.
159 lines
No EOL
4.7 KiB
PHP
159 lines
No EOL
4.7 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() {
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: Constructor started.');
|
|
$this->define_constants();
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: define_constants completed.');
|
|
$this->includes();
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: includes completed.');
|
|
$this->init_hooks();
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: init_hooks completed.');
|
|
}
|
|
|
|
/**
|
|
* Define constants
|
|
*/
|
|
private function define_constants() {
|
|
// Additional constants can be defined here
|
|
}
|
|
|
|
/**
|
|
* Include required files
|
|
*/
|
|
private function includes() {
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: includes method started.');
|
|
$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;
|
|
error_log("[HVAC DEBUG] HVAC_Community_Events: Included file {$file}.");
|
|
} else {
|
|
error_log("[HVAC DEBUG] HVAC_Community_Events: Failed to include file {$file}. File not found.");
|
|
}
|
|
}
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: includes method completed.');
|
|
}
|
|
|
|
/**
|
|
* 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() {
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: init method started.');
|
|
// Initialize handlers
|
|
new \HVAC_Community_Events\Community\Login_Handler();
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: Initialized Login_Handler.');
|
|
new HVAC_Registration();
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: Initialized HVAC_Registration.');
|
|
error_log('[HVAC DEBUG] HVAC_Community_Events: init method completed.');
|
|
|
|
// 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
|