- 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>
391 lines
No EOL
12 KiB
PHP
391 lines
No EOL
12 KiB
PHP
<?php
|
|
/**
|
|
* HVAC Shortcodes Manager
|
|
*
|
|
* Centralized management of all plugin shortcodes
|
|
*
|
|
* @package HVAC_Community_Events
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* HVAC_Shortcodes class
|
|
*/
|
|
class HVAC_Shortcodes {
|
|
|
|
/**
|
|
* Instance
|
|
*
|
|
* @var HVAC_Shortcodes
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Registered shortcodes
|
|
*
|
|
* @var array
|
|
*/
|
|
private $shortcodes = array();
|
|
|
|
/**
|
|
* Get instance
|
|
*
|
|
* @return HVAC_Shortcodes
|
|
*/
|
|
public static function instance() {
|
|
if (null === self::$instance) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
private function __construct() {
|
|
$this->define_shortcodes();
|
|
$this->register_shortcodes();
|
|
}
|
|
|
|
/**
|
|
* Define all plugin shortcodes
|
|
*
|
|
* @return void
|
|
*/
|
|
private function define_shortcodes() {
|
|
$this->shortcodes = array(
|
|
// Dashboard shortcodes
|
|
'hvac_dashboard' => array(
|
|
'callback' => array($this, 'render_dashboard'),
|
|
'description' => 'Trainer dashboard'
|
|
),
|
|
'hvac_master_dashboard' => array(
|
|
'callback' => array($this, 'render_master_dashboard'),
|
|
'description' => 'Master trainer dashboard'
|
|
),
|
|
|
|
// Event management shortcodes
|
|
'hvac_manage_event' => array(
|
|
'callback' => array($this, 'render_manage_event'),
|
|
'description' => 'Event management form'
|
|
),
|
|
'hvac_event_summary' => array(
|
|
'callback' => array($this, 'render_event_summary'),
|
|
'description' => 'Event summary page'
|
|
),
|
|
|
|
// Authentication shortcodes
|
|
'hvac_community_login' => array(
|
|
'callback' => array($this, 'render_login'),
|
|
'description' => 'Community login form'
|
|
),
|
|
'hvac_trainer_registration' => array(
|
|
'callback' => array($this, 'render_registration'),
|
|
'description' => 'Trainer registration form'
|
|
),
|
|
|
|
// Profile shortcodes
|
|
'hvac_trainer_profile' => array(
|
|
'callback' => array($this, 'render_trainer_profile'),
|
|
'description' => 'Trainer profile page'
|
|
),
|
|
|
|
// Certificate shortcodes
|
|
'hvac_certificate_reports' => array(
|
|
'callback' => array($this, 'render_certificate_reports'),
|
|
'description' => 'Certificate reports page'
|
|
),
|
|
'hvac_generate_certificates' => array(
|
|
'callback' => array($this, 'render_generate_certificates'),
|
|
'description' => 'Certificate generation page'
|
|
),
|
|
|
|
// Communication shortcodes
|
|
'hvac_email_attendees' => array(
|
|
'callback' => array($this, 'render_email_attendees'),
|
|
'description' => 'Email attendees interface'
|
|
),
|
|
'hvac_communication_templates' => array(
|
|
'callback' => array($this, 'render_communication_templates'),
|
|
'description' => 'Communication templates management'
|
|
),
|
|
'hvac_communication_schedules' => array(
|
|
'callback' => array($this, 'render_communication_schedules'),
|
|
'description' => 'Communication schedules management'
|
|
),
|
|
|
|
// Admin shortcodes
|
|
'hvac_google_sheets' => array(
|
|
'callback' => array($this, 'render_google_sheets_admin'),
|
|
'description' => 'Google Sheets integration admin'
|
|
),
|
|
);
|
|
|
|
// Allow filtering of shortcode definitions
|
|
$this->shortcodes = apply_filters('hvac_shortcode_definitions', $this->shortcodes);
|
|
}
|
|
|
|
/**
|
|
* Register all shortcodes
|
|
*
|
|
* @return void
|
|
*/
|
|
private function register_shortcodes() {
|
|
foreach ($this->shortcodes as $tag => $config) {
|
|
add_shortcode($tag, $config['callback']);
|
|
}
|
|
|
|
// Log registration
|
|
HVAC_Logger::info('Registered ' . count($this->shortcodes) . ' shortcodes', 'Shortcodes');
|
|
}
|
|
|
|
/**
|
|
* Get registered shortcodes
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_shortcodes() {
|
|
return $this->shortcodes;
|
|
}
|
|
|
|
/**
|
|
* Check if shortcode is registered
|
|
*
|
|
* @param string $tag Shortcode tag
|
|
* @return bool
|
|
*/
|
|
public function is_registered($tag) {
|
|
return isset($this->shortcodes[$tag]);
|
|
}
|
|
|
|
// ========================================
|
|
// Shortcode Render Methods
|
|
// ========================================
|
|
|
|
/**
|
|
* Render dashboard shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_dashboard($atts = array()) {
|
|
if (!class_exists('HVAC_Dashboard')) {
|
|
return '<p>' . __('Dashboard functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$dashboard = new HVAC_Dashboard();
|
|
return $dashboard->render_dashboard($atts);
|
|
}
|
|
|
|
/**
|
|
* Render master dashboard shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_master_dashboard($atts = array()) {
|
|
if (!class_exists('HVAC_Master_Dashboard')) {
|
|
return '<p>' . __('Master dashboard functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$master_dashboard = new HVAC_Master_Dashboard();
|
|
return $master_dashboard->render_dashboard($atts);
|
|
}
|
|
|
|
/**
|
|
* Render manage event shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_manage_event($atts = array()) {
|
|
if (!class_exists('HVAC_Manage_Event')) {
|
|
return '<p>' . __('Event management functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$manage_event = new HVAC_Manage_Event();
|
|
return $manage_event->render_form($atts);
|
|
}
|
|
|
|
/**
|
|
* Render event summary shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_event_summary($atts = array()) {
|
|
if (!class_exists('HVAC_Event_Summary')) {
|
|
return '<p>' . __('Event summary functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$event_summary = new HVAC_Event_Summary();
|
|
return $event_summary->render_summary($atts);
|
|
}
|
|
|
|
/**
|
|
* Render login shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_login($atts = array()) {
|
|
if (!class_exists('\\HVAC_Community_Events\\Community\\Login_Handler')) {
|
|
return '<p>' . __('Login functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$login_handler = new \HVAC_Community_Events\Community\Login_Handler();
|
|
return $login_handler->render_login_form($atts);
|
|
}
|
|
|
|
/**
|
|
* Render registration shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_registration($atts = array()) {
|
|
if (!class_exists('HVAC_Registration')) {
|
|
return '<p>' . __('Registration functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$registration = new HVAC_Registration();
|
|
return $registration->render_registration_form($atts);
|
|
}
|
|
|
|
/**
|
|
* Render trainer profile shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_trainer_profile($atts = array()) {
|
|
if (!class_exists('HVAC_Trainer_Profile')) {
|
|
return '<p>' . __('Profile functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$trainer_profile = new HVAC_Trainer_Profile();
|
|
return $trainer_profile->render_profile($atts);
|
|
}
|
|
|
|
/**
|
|
* Render certificate reports shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_certificate_reports($atts = array()) {
|
|
// Redirect to manager if available
|
|
if (class_exists('HVAC_Certificate_Manager')) {
|
|
$cert_manager = new HVAC_Certificate_Manager();
|
|
return $cert_manager->render_reports_page();
|
|
}
|
|
|
|
return '<p>' . __('Certificate reports functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
/**
|
|
* Render generate certificates shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_generate_certificates($atts = array()) {
|
|
// Redirect to manager if available
|
|
if (class_exists('HVAC_Certificate_Manager')) {
|
|
$cert_manager = new HVAC_Certificate_Manager();
|
|
return $cert_manager->render_generate_page();
|
|
}
|
|
|
|
return '<p>' . __('Certificate generation functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
/**
|
|
* Render email attendees shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_email_attendees($atts = array()) {
|
|
// Check if user has appropriate permissions
|
|
if (!current_user_can('edit_tribe_events')) {
|
|
return '<p>' . __('You do not have permission to access this page.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
ob_start();
|
|
include HVAC_PLUGIN_DIR . 'templates/email-attendees.php';
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Render communication templates shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_communication_templates($atts = array()) {
|
|
if (!class_exists('HVAC_Communication_Templates')) {
|
|
return '<p>' . __('Communication templates functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
// Check permissions
|
|
if (!current_user_can('edit_tribe_events') && !current_user_can('manage_options')) {
|
|
return '<p>' . __('You do not have permission to access this page.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$templates = new HVAC_Communication_Templates();
|
|
|
|
ob_start();
|
|
$templates->render_admin_page();
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Render communication schedules shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_communication_schedules($atts = array()) {
|
|
if (!class_exists('HVAC_Communication_Scheduler')) {
|
|
return '<p>' . __('Communication scheduler functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
// Check permissions
|
|
if (!current_user_can('edit_tribe_events') && !current_user_can('manage_options')) {
|
|
return '<p>' . __('You do not have permission to access this page.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$scheduler = hvac_communication_scheduler();
|
|
|
|
ob_start();
|
|
$scheduler->render_schedules_page();
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Render Google Sheets admin shortcode
|
|
*
|
|
* @param array $atts Shortcode attributes
|
|
* @return string
|
|
*/
|
|
public function render_google_sheets_admin($atts = array()) {
|
|
if (!class_exists('HVAC_Google_Sheets_Admin')) {
|
|
return '<p>' . __('Google Sheets functionality not available.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
// Check permissions
|
|
if (!current_user_can('manage_options') && !current_user_can('view_all_trainer_data')) {
|
|
return '<p>' . __('You do not have permission to access this page.', 'hvac-community-events') . '</p>';
|
|
}
|
|
|
|
$google_sheets = new HVAC_Google_Sheets_Admin();
|
|
|
|
ob_start();
|
|
$google_sheets->render_admin_page();
|
|
return ob_get_clean();
|
|
}
|
|
} |