upskill-event-manager/includes/class-hvac-shortcodes.php
bengizmo 40274d98ad feat: Implement comprehensive user role field and certification tracking system
• Add user role field to registration, profile display, and profile edit
  - 10 role options: technician, installer, supervisor, manager, trainer, consultant, sales rep, engineer, business owner, other
  - Required field with server-side validation
  - Radio buttons in registration, dropdown in profile edit
  - Displays in profile with proper capitalization

• Implement advanced certification tracking system
  - Date Certified: HTML5 date picker with validation (no future dates)
  - Certification Type: dropdown with "Certified measureQuick Trainer" and "Certified measureQuick Champion"
  - Certification Status: color-coded status badges (Active/Expired/Pending/Disabled)

• Add sophisticated role-based access control
  - Regular trainers: read-only access to certification fields
  - Administrators & master trainers: full edit access to certification fields
  - Visual indicators for read-only fields
  - Server-side permission validation

• Enhance plugin activation system
  - Initialize all 36 user meta fields for existing users
  - Smart default assignment based on user capabilities
  - Backward compatibility maintained

• Add professional UI styling
  - Blue-bordered certification section with trophy icon
  - Color-coded status badges with proper contrast
  - Read-only field styling with visual indicators
  - Enhanced form controls with focus states

• Comprehensive testing and documentation
  - E2E test coverage with visual verification
  - Updated API reference with new meta fields
  - Access control patterns documented
  - 100% test pass rate on staging environment

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-01 10:52:11 -03:00

621 lines
No EOL
22 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'
),
// Venue shortcodes
'hvac_trainer_venues_list' => array(
'callback' => array($this, 'render_venues_list'),
'description' => 'Trainer venues listing page'
),
'hvac_trainer_venue_manage' => array(
'callback' => array($this, 'render_venue_manage'),
'description' => 'Trainer venue management page'
),
// Organizer shortcodes
'hvac_trainer_organizers_list' => array(
'callback' => array($this, 'render_organizers_list'),
'description' => 'Trainer organizers listing page'
),
'hvac_trainer_organizer_manage' => array(
'callback' => array($this, 'render_organizer_manage'),
'description' => 'Trainer organizer management page'
),
// Profile shortcodes - additional ones beyond hvac_trainer_profile
'hvac_trainer_profile_view' => array(
'callback' => array($this, 'render_trainer_profile_view'),
'description' => 'Trainer profile view page'
),
'hvac_trainer_profile_edit' => array(
'callback' => array($this, 'render_trainer_profile_edit'),
'description' => 'Trainer profile edit page'
),
// 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()) {
// Add debug comment to verify this method is being called
$debug = '<!-- HVAC_Shortcodes::render_dashboard called -->';
// Use the HVAC_Community_Events instance method
if (class_exists('HVAC_Community_Events')) {
$hvac = HVAC_Community_Events::get_instance();
if (method_exists($hvac, 'render_dashboard')) {
return $debug . $hvac->render_dashboard();
}
}
// Fallback if class not available
if (!is_user_logged_in()) {
return $debug . '<p>' . __('Please log in to view the dashboard.', 'hvac-community-events') . '</p>';
}
// Include the dashboard template
ob_start();
include HVAC_PLUGIN_DIR . 'templates/template-hvac-dashboard.php';
return ob_get_clean();
}
/**
* Render master dashboard shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_master_dashboard($atts = array()) {
// Add debug comment to verify this method is being called
$debug = '<!-- HVAC_Shortcodes::render_master_dashboard called -->';
// Use the HVAC_Community_Events instance method
if (class_exists('HVAC_Community_Events')) {
$hvac = HVAC_Community_Events::get_instance();
if (method_exists($hvac, 'render_master_dashboard')) {
return $debug . $hvac->render_master_dashboard();
}
}
// Fallback if class not available
if (!is_user_logged_in()) {
return $debug . '<p>' . __('Please log in to view the master dashboard.', 'hvac-community-events') . '</p>';
}
if (!current_user_can('view_master_dashboard') && !current_user_can('view_all_trainer_data') && !current_user_can('administrator')) {
return $debug . '<div class="hvac-error">' . __('You do not have permission to view the master dashboard. This dashboard is only available to Master Trainers and Administrators.', 'hvac-community-events') . '</div>';
}
// Include the master dashboard template
ob_start();
include HVAC_PLUGIN_DIR . 'templates/template-hvac-master-dashboard.php';
return ob_get_clean();
}
/**
* Render manage event shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_manage_event($atts = array()) {
// The manage event page uses The Events Calendar Community Events shortcode
// This shortcode is just a placeholder since the actual functionality
// is handled by the tribe_community_events shortcode
if (!shortcode_exists('tribe_community_events')) {
return '<p>' . __('Event management requires The Events Calendar Community Events add-on.', 'hvac-community-events') . '</p>';
}
// Return the tribe shortcode
return '[tribe_community_events]';
}
/**
* 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()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to view certificate reports.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
// Include the certificate reports content template
ob_start();
include HVAC_PLUGIN_DIR . 'templates/certificates/certificate-reports-content.php';
return ob_get_clean();
}
/**
* Render generate certificates shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_generate_certificates($atts = array()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to generate certificates.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
// Include the generate certificates content template
ob_start();
include HVAC_PLUGIN_DIR . 'templates/certificates/generate-certificates-content.php';
return ob_get_clean();
}
/**
* Render email attendees shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_email_attendees($atts = array()) {
// Check if user has appropriate permissions
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer 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();
}
/**
* Render venues list shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_venues_list($atts = array()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to view venues.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
if (!class_exists('HVAC_Venues')) {
return '<p>' . __('Venues functionality not available.', 'hvac-community-events') . '</p>';
}
$venues = new HVAC_Venues();
return $venues->render_venues_list($atts);
}
/**
* Render venue manage shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_venue_manage($atts = array()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to manage venues.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
if (!class_exists('HVAC_Venues')) {
return '<p>' . __('Venues functionality not available.', 'hvac-community-events') . '</p>';
}
$venues = new HVAC_Venues();
return $venues->render_venue_manage($atts);
}
/**
* Render organizers list shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_organizers_list($atts = array()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to view organizers.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
if (!class_exists('HVAC_Organizers')) {
return '<p>' . __('Organizers functionality not available.', 'hvac-community-events') . '</p>';
}
$organizers = new HVAC_Organizers();
return $organizers->render_organizers_list($atts);
}
/**
* Render organizer manage shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_organizer_manage($atts = array()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to manage organizers.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
if (!class_exists('HVAC_Organizers')) {
return '<p>' . __('Organizers functionality not available.', 'hvac-community-events') . '</p>';
}
$organizers = new HVAC_Organizers();
return $organizers->render_organizer_manage($atts);
}
/**
* Render trainer profile view shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_trainer_profile_view($atts = array()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to view your profile.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
if (!class_exists('HVAC_Trainer_Profile_Manager')) {
return '<p>' . __('Profile functionality not available.', 'hvac-community-events') . '</p>';
}
$profile_manager = new HVAC_Trainer_Profile_Manager();
return $profile_manager->render_profile_view($atts);
}
/**
* Render trainer profile edit shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_trainer_profile_edit($atts = array()) {
// Check permissions
if (!is_user_logged_in()) {
return '<p>' . __('Please log in to edit your profile.', 'hvac-community-events') . '</p>';
}
// Allow trainers, master trainers, or WordPress admins
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
return '<p>' . __('You must be a trainer to access this page.', 'hvac-community-events') . '</p>';
}
if (!class_exists('HVAC_Trainer_Profile_Manager')) {
return '<p>' . __('Profile functionality not available.', 'hvac-community-events') . '</p>';
}
$profile_manager = new HVAC_Trainer_Profile_Manager();
return $profile_manager->render_profile_edit($atts);
}
}