- Create HVAC_Shortcodes class to centralize shortcode management - Create HVAC_Scripts_Styles class for all script/style enqueuing - Create HVAC_Route_Manager class for URL routing and redirects - Update HVAC_Plugin to use new architecture components - Remove duplicate functionality from HVAC_Community_Events - Add comprehensive refactoring plan documentation This refactoring resolves duplicate initialization issues and creates a cleaner, more maintainable architecture with clear separation of concerns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
501 lines
No EOL
16 KiB
PHP
501 lines
No EOL
16 KiB
PHP
<?php
|
|
/**
|
|
* Main Plugin Class for HVAC Community Events
|
|
*
|
|
* @package HVAC_Community_Events
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* HVAC_Plugin class
|
|
*/
|
|
class HVAC_Plugin {
|
|
|
|
/**
|
|
* Plugin instance
|
|
*
|
|
* @var HVAC_Plugin
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Get plugin instance
|
|
*
|
|
* @return HVAC_Plugin
|
|
*/
|
|
public static function instance() {
|
|
if (null === self::$instance) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
private function __construct() {
|
|
$this->define_constants();
|
|
$this->includes();
|
|
$this->init_hooks();
|
|
}
|
|
|
|
/**
|
|
* Define plugin constants
|
|
*
|
|
* @return void
|
|
*/
|
|
private function define_constants() {
|
|
if (!defined('HVAC_PLUGIN_VERSION')) {
|
|
define('HVAC_PLUGIN_VERSION', '1.0.1');
|
|
}
|
|
if (!defined('HVAC_PLUGIN_FILE')) {
|
|
define('HVAC_PLUGIN_FILE', dirname(__DIR__) . '/hvac-community-events.php');
|
|
}
|
|
if (!defined('HVAC_PLUGIN_DIR')) {
|
|
define('HVAC_PLUGIN_DIR', plugin_dir_path(HVAC_PLUGIN_FILE));
|
|
}
|
|
if (!defined('HVAC_PLUGIN_URL')) {
|
|
define('HVAC_PLUGIN_URL', plugin_dir_url(HVAC_PLUGIN_FILE));
|
|
}
|
|
if (!defined('HVAC_PLUGIN_BASENAME')) {
|
|
define('HVAC_PLUGIN_BASENAME', plugin_basename(HVAC_PLUGIN_FILE));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Include required files
|
|
*
|
|
* @return void
|
|
*/
|
|
private function includes() {
|
|
// Core includes
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-logger.php';
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-activator.php';
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-deactivator.php';
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-page-manager.php';
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-template-loader.php';
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-community-events.php';
|
|
|
|
// Check which roles manager exists
|
|
if (file_exists(HVAC_PLUGIN_DIR . 'includes/class-hvac-roles-manager.php')) {
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-roles-manager.php';
|
|
} elseif (file_exists(HVAC_PLUGIN_DIR . 'includes/class-hvac-roles.php')) {
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-roles.php';
|
|
}
|
|
|
|
// Core architecture includes
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-shortcodes.php';
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-scripts-styles.php';
|
|
require_once HVAC_PLUGIN_DIR . 'includes/class-hvac-route-manager.php';
|
|
|
|
// Feature includes - check if files exist before including
|
|
$feature_includes = [
|
|
'class-hvac-trainer-status.php',
|
|
'class-hvac-access-control.php',
|
|
'class-hvac-registration.php',
|
|
'class-hvac-manage-event.php',
|
|
'class-hvac-event-summary.php',
|
|
'class-hvac-trainer-profile.php',
|
|
'class-hvac-master-dashboard.php',
|
|
'class-hvac-master-dashboard-data.php',
|
|
'class-hvac-settings.php',
|
|
'class-hvac-dashboard.php',
|
|
'class-hvac-dashboard-data.php',
|
|
'class-hvac-approval-workflow.php',
|
|
'class-hvac-event-navigation.php',
|
|
'class-hvac-event-manage-header.php',
|
|
'class-hvac-help-system.php',
|
|
'class-event-form-handler.php',
|
|
'class-event-author-fixer.php',
|
|
'class-attendee-profile.php',
|
|
];
|
|
|
|
foreach ($feature_includes as $file) {
|
|
$file_path = HVAC_PLUGIN_DIR . 'includes/' . $file;
|
|
if (file_exists($file_path)) {
|
|
require_once $file_path;
|
|
}
|
|
}
|
|
|
|
// Community includes
|
|
if (file_exists(HVAC_PLUGIN_DIR . 'includes/community/class-login-handler.php')) {
|
|
require_once HVAC_PLUGIN_DIR . 'includes/community/class-login-handler.php';
|
|
// Initialize Login_Handler to register shortcode
|
|
new \HVAC_Community_Events\Community\Login_Handler();
|
|
}
|
|
if (file_exists(HVAC_PLUGIN_DIR . 'includes/community/class-event-handler.php')) {
|
|
require_once HVAC_PLUGIN_DIR . 'includes/community/class-event-handler.php';
|
|
}
|
|
|
|
// Certificate system
|
|
$certificate_files = [
|
|
'certificates/class-certificate-security.php',
|
|
'certificates/class-certificate-installer.php',
|
|
'certificates/class-certificate-manager.php',
|
|
'certificates/class-certificate-generator.php',
|
|
'certificates/class-certificate-url-handler.php',
|
|
];
|
|
|
|
foreach ($certificate_files as $file) {
|
|
$file_path = HVAC_PLUGIN_DIR . 'includes/' . $file;
|
|
if (file_exists($file_path)) {
|
|
require_once $file_path;
|
|
}
|
|
}
|
|
|
|
// Admin includes
|
|
$admin_files = [
|
|
'admin/class-zoho-admin.php',
|
|
'admin/class-admin-dashboard.php',
|
|
'admin/class-hvac-enhanced-settings.php',
|
|
];
|
|
|
|
foreach ($admin_files as $file) {
|
|
$file_path = HVAC_PLUGIN_DIR . 'includes/' . $file;
|
|
if (file_exists($file_path)) {
|
|
require_once $file_path;
|
|
}
|
|
}
|
|
|
|
// Google Sheets integration
|
|
$google_files = [
|
|
'google-sheets/class-google-sheets-auth.php',
|
|
'google-sheets/class-google-sheets-admin.php',
|
|
];
|
|
|
|
foreach ($google_files as $file) {
|
|
$file_path = HVAC_PLUGIN_DIR . 'includes/' . $file;
|
|
if (file_exists($file_path)) {
|
|
require_once $file_path;
|
|
}
|
|
}
|
|
|
|
// Communication system
|
|
$communication_files = [
|
|
'communication/class-communication-installer.php',
|
|
'communication/class-communication-scheduler.php',
|
|
'communication/class-communication-templates.php',
|
|
];
|
|
|
|
foreach ($communication_files as $file) {
|
|
$file_path = HVAC_PLUGIN_DIR . 'includes/' . $file;
|
|
if (file_exists($file_path)) {
|
|
require_once $file_path;
|
|
}
|
|
}
|
|
|
|
// Helper includes
|
|
if (file_exists(HVAC_PLUGIN_DIR . 'includes/helpers/attendee-profile-link.php')) {
|
|
require_once HVAC_PLUGIN_DIR . 'includes/helpers/attendee-profile-link.php';
|
|
}
|
|
|
|
// Legacy support
|
|
$this->include_legacy_files();
|
|
}
|
|
|
|
/**
|
|
* Include legacy files for backward compatibility
|
|
*
|
|
* @return void
|
|
*/
|
|
private function include_legacy_files() {
|
|
// Include legacy functions if they exist
|
|
$legacy_files = [
|
|
'includes/hvac-ce-functions.php',
|
|
'includes/hvac-ce-admin.php',
|
|
'includes/hvac-ce-certificates.php'
|
|
];
|
|
|
|
foreach ($legacy_files as $file) {
|
|
$file_path = HVAC_PLUGIN_DIR . $file;
|
|
if (file_exists($file_path)) {
|
|
require_once $file_path;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Initialize hooks
|
|
*
|
|
* @return void
|
|
*/
|
|
private function init_hooks() {
|
|
// Activation/Deactivation hooks
|
|
register_activation_hook(HVAC_PLUGIN_FILE, [$this, 'activate']);
|
|
register_deactivation_hook(HVAC_PLUGIN_FILE, [$this, 'deactivate']);
|
|
|
|
// Init hook
|
|
add_action('init', [$this, 'init'], 0);
|
|
|
|
// Plugin loaded
|
|
add_action('plugins_loaded', [$this, 'plugins_loaded']);
|
|
|
|
// Admin init
|
|
add_action('admin_init', [$this, 'admin_init']);
|
|
|
|
// AJAX handlers
|
|
add_action('wp_ajax_hvac_master_dashboard_events', [$this, 'ajax_master_dashboard_events']);
|
|
add_action('wp_ajax_nopriv_hvac_master_dashboard_events', [$this, 'ajax_master_dashboard_events']);
|
|
}
|
|
|
|
/**
|
|
* Plugin activation
|
|
*
|
|
* @return void
|
|
*/
|
|
public function activate() {
|
|
HVAC_Activator::activate();
|
|
}
|
|
|
|
/**
|
|
* Plugin deactivation
|
|
*
|
|
* @return void
|
|
*/
|
|
public function deactivate() {
|
|
HVAC_Deactivator::deactivate();
|
|
}
|
|
|
|
/**
|
|
* Init hook
|
|
*
|
|
* @return void
|
|
*/
|
|
public function init() {
|
|
// Initialize core architecture components
|
|
HVAC_Shortcodes::instance();
|
|
HVAC_Scripts_Styles::instance();
|
|
HVAC_Route_Manager::instance();
|
|
|
|
// Initialize template loader
|
|
HVAC_Template_Loader::init();
|
|
|
|
// Initialize access control
|
|
new HVAC_Access_Control();
|
|
|
|
// Initialize other components
|
|
$this->init_components();
|
|
|
|
// Ensure registration page access
|
|
add_action('template_redirect', [$this, 'ensure_registration_access'], 5);
|
|
}
|
|
|
|
/**
|
|
* Initialize plugin components
|
|
*
|
|
* @return void
|
|
*/
|
|
private function init_components() {
|
|
// Initialize the main community events class (registers shortcodes)
|
|
if (class_exists('HVAC_Community_Events')) {
|
|
HVAC_Community_Events::instance();
|
|
}
|
|
|
|
// Initialize registration if class exists
|
|
if (class_exists('HVAC_Registration')) {
|
|
new HVAC_Registration();
|
|
}
|
|
|
|
// Initialize event management
|
|
if (class_exists('HVAC_Manage_Event')) {
|
|
new HVAC_Manage_Event();
|
|
}
|
|
if (class_exists('HVAC_Event_Summary')) {
|
|
new HVAC_Event_Summary();
|
|
}
|
|
|
|
// Initialize trainer profile
|
|
if (class_exists('HVAC_Trainer_Profile')) {
|
|
new HVAC_Trainer_Profile();
|
|
}
|
|
|
|
// Initialize dashboards
|
|
if (class_exists('HVAC_Dashboard')) {
|
|
new HVAC_Dashboard();
|
|
}
|
|
if (class_exists('HVAC_Master_Dashboard')) {
|
|
new HVAC_Master_Dashboard();
|
|
}
|
|
|
|
// Initialize settings
|
|
if (class_exists('HVAC_Settings')) {
|
|
new HVAC_Settings();
|
|
}
|
|
|
|
// Initialize approval workflow
|
|
if (class_exists('HVAC_Approval_Workflow')) {
|
|
new HVAC_Approval_Workflow();
|
|
}
|
|
|
|
// Initialize event navigation
|
|
if (class_exists('HVAC_Event_Navigation')) {
|
|
new HVAC_Event_Navigation();
|
|
}
|
|
|
|
// Initialize help system
|
|
if (class_exists('HVAC_Help_System')) {
|
|
HVAC_Help_System::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();
|
|
}
|
|
|
|
// Initialize attendee profile
|
|
if (class_exists('HVAC_Attendee_Profile')) {
|
|
HVAC_Attendee_Profile::instance();
|
|
}
|
|
|
|
// Initialize Google Sheets
|
|
if (class_exists('HVAC_Google_Sheets_Auth')) {
|
|
new HVAC_Google_Sheets_Auth();
|
|
}
|
|
if (class_exists('HVAC_Google_Sheets_Admin')) {
|
|
new HVAC_Google_Sheets_Admin();
|
|
}
|
|
|
|
// Initialize communication system
|
|
if (class_exists('HVAC_Communication_Installer')) {
|
|
HVAC_Communication_Installer::maybe_update();
|
|
}
|
|
if (class_exists('HVAC_Communication_Scheduler')) {
|
|
hvac_communication_scheduler();
|
|
}
|
|
|
|
// Initialize admin components
|
|
if (is_admin()) {
|
|
if (class_exists('HVAC_Zoho_Admin')) {
|
|
HVAC_Zoho_Admin::instance();
|
|
}
|
|
if (class_exists('HVAC_Admin_Dashboard')) {
|
|
new HVAC_Admin_Dashboard();
|
|
}
|
|
if (class_exists('HVAC_Enhanced_Settings')) {
|
|
HVAC_Enhanced_Settings::instance();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Plugins loaded hook
|
|
*
|
|
* @return void
|
|
*/
|
|
public function plugins_loaded() {
|
|
// Load text domain
|
|
load_plugin_textdomain('hvac-community-events', false, dirname(HVAC_PLUGIN_BASENAME) . '/languages');
|
|
}
|
|
|
|
/**
|
|
* Admin init hook
|
|
*
|
|
* @return void
|
|
*/
|
|
public function admin_init() {
|
|
// Check for plugin updates
|
|
$this->check_plugin_updates();
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Check for plugin updates
|
|
*
|
|
* @return void
|
|
*/
|
|
private function check_plugin_updates() {
|
|
$current_version = get_option('hvac_plugin_version', '0.0.0');
|
|
|
|
if (version_compare($current_version, HVAC_PLUGIN_VERSION, '<')) {
|
|
// Run upgrade routines
|
|
$this->upgrade($current_version);
|
|
|
|
// Update version
|
|
update_option('hvac_plugin_version', HVAC_PLUGIN_VERSION);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Run upgrade routines
|
|
*
|
|
* @param string $from_version Version upgrading from
|
|
* @return void
|
|
*/
|
|
private function upgrade($from_version) {
|
|
HVAC_Logger::info("Upgrading from version {$from_version} to " . HVAC_PLUGIN_VERSION, 'Upgrade');
|
|
|
|
// Version-specific upgrades can be added here
|
|
}
|
|
|
|
|
|
/**
|
|
* Ensure trainer registration page is publicly accessible
|
|
*
|
|
* @return void
|
|
*/
|
|
public function ensure_registration_access() {
|
|
// If we're on the trainer registration page, don't apply any authentication checks
|
|
if (is_page('trainer/registration')) {
|
|
// Remove any potential authentication hooks that might be added by other code
|
|
remove_all_actions('template_redirect', 10);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle AJAX request for master dashboard events table
|
|
*
|
|
* @return void
|
|
*/
|
|
public function ajax_master_dashboard_events() {
|
|
// Verify nonce
|
|
if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'hvac_master_dashboard_nonce')) {
|
|
wp_die('Security check failed');
|
|
}
|
|
|
|
// Check permissions
|
|
if (!current_user_can('view_master_dashboard') && !current_user_can('view_all_trainer_data') && !current_user_can('manage_options')) {
|
|
wp_send_json_error('Insufficient permissions');
|
|
}
|
|
|
|
// Load master dashboard data class if needed
|
|
if (!class_exists('HVAC_Master_Dashboard_Data')) {
|
|
$data_file = HVAC_PLUGIN_DIR . 'includes/class-hvac-master-dashboard-data.php';
|
|
if (file_exists($data_file)) {
|
|
require_once $data_file;
|
|
}
|
|
}
|
|
|
|
if (!class_exists('HVAC_Master_Dashboard_Data')) {
|
|
wp_send_json_error('Master dashboard data class not found');
|
|
}
|
|
|
|
// Initialize data handler
|
|
$master_data = new HVAC_Master_Dashboard_Data();
|
|
|
|
// Get table data with filters
|
|
$args = array(
|
|
'status' => sanitize_text_field($_POST['status'] ?? 'all'),
|
|
'search' => sanitize_text_field($_POST['search'] ?? ''),
|
|
'orderby' => sanitize_text_field($_POST['orderby'] ?? 'date'),
|
|
'order' => sanitize_text_field($_POST['order'] ?? 'DESC'),
|
|
'page' => absint($_POST['page'] ?? 1),
|
|
'per_page' => absint($_POST['per_page'] ?? 10),
|
|
'date_from' => sanitize_text_field($_POST['date_from'] ?? ''),
|
|
'date_to' => sanitize_text_field($_POST['date_to'] ?? ''),
|
|
'trainer_id' => absint($_POST['trainer_id'] ?? 0),
|
|
);
|
|
|
|
$table_data = $master_data->get_events_table_data($args);
|
|
wp_send_json_success($table_data);
|
|
}
|
|
} |