• 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>
369 lines
No EOL
12 KiB
PHP
369 lines
No EOL
12 KiB
PHP
<?php
|
|
/**
|
|
* HVAC Menu System
|
|
*
|
|
* Implements proper WordPress menu API for HVAC trainer pages
|
|
* Following WordPress best practices for menu registration and display
|
|
*
|
|
* @package HVAC_Community_Events
|
|
* @since 2.0.0
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class HVAC_Menu_System {
|
|
|
|
/**
|
|
* Plugin instance
|
|
*
|
|
* @var HVAC_Menu_System
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Get plugin instance
|
|
*
|
|
* @return HVAC_Menu_System
|
|
*/
|
|
public static function instance() {
|
|
if (null === self::$instance) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public function __construct() {
|
|
add_action('init', array($this, 'register_menu_locations'));
|
|
add_action('wp', array($this, 'setup_trainer_menu'));
|
|
add_action('wp_enqueue_scripts', array($this, 'enqueue_menu_styles'));
|
|
add_filter('wp_nav_menu_items', array($this, 'add_logout_to_menu'), 10, 2);
|
|
}
|
|
|
|
/**
|
|
* Register menu locations
|
|
*/
|
|
public function register_menu_locations() {
|
|
register_nav_menus(array(
|
|
'hvac_trainer_menu' => __('HVAC Trainer Navigation', 'hvac-community-events'),
|
|
));
|
|
}
|
|
|
|
/**
|
|
* Setup trainer menu on appropriate pages
|
|
*/
|
|
public function setup_trainer_menu() {
|
|
// Menu will be rendered directly in templates, not injected via JavaScript
|
|
}
|
|
|
|
/**
|
|
* Check if current page is a trainer page
|
|
*/
|
|
private function is_trainer_page() {
|
|
global $wp;
|
|
$current_url = home_url(add_query_arg(array(), $wp->request));
|
|
return (strpos($current_url, '/trainer/') !== false || strpos($current_url, '/master-trainer/') !== false);
|
|
}
|
|
|
|
/**
|
|
* Check if user can access trainer area
|
|
*/
|
|
private function user_can_access_trainer_area() {
|
|
if (!is_user_logged_in()) {
|
|
return false;
|
|
}
|
|
|
|
return current_user_can('hvac_trainer') ||
|
|
current_user_can('hvac_master_trainer') ||
|
|
current_user_can('manage_options');
|
|
}
|
|
|
|
/**
|
|
* Render the trainer menu
|
|
*/
|
|
public function render_trainer_menu() {
|
|
if (!$this->user_can_access_trainer_area()) {
|
|
return;
|
|
}
|
|
|
|
// Check if we're already showing a navigation menu
|
|
if (defined('HVAC_NAV_RENDERED') && HVAC_NAV_RENDERED) {
|
|
return;
|
|
}
|
|
|
|
// Mark that navigation has been rendered
|
|
define('HVAC_NAV_RENDERED', true);
|
|
|
|
$menu_items = $this->get_menu_structure();
|
|
|
|
echo '<div class="hvac-trainer-menu-wrapper">';
|
|
echo '<nav class="hvac-trainer-nav" role="navigation">';
|
|
echo '<ul class="hvac-trainer-menu">';
|
|
|
|
foreach ($menu_items as $item) {
|
|
$this->render_menu_item($item);
|
|
}
|
|
|
|
echo '</ul>';
|
|
echo '</nav>';
|
|
echo '</div>';
|
|
}
|
|
|
|
/**
|
|
* Get menu structure based on user capabilities
|
|
*/
|
|
private function get_menu_structure() {
|
|
$user = wp_get_current_user();
|
|
$is_master = in_array('hvac_master_trainer', $user->roles) || current_user_can('manage_options');
|
|
|
|
// If user has master trainer role, ALWAYS show master menu
|
|
// This prevents duplicate navigation for dual-role users
|
|
if ($is_master) {
|
|
return $this->get_master_menu_structure();
|
|
}
|
|
|
|
$menu = array(
|
|
array(
|
|
'title' => 'Events',
|
|
'url' => '#',
|
|
'icon' => 'dashicons-calendar-alt',
|
|
'children' => array(
|
|
array(
|
|
'title' => 'Dashboard',
|
|
'url' => home_url('/trainer/dashboard/'),
|
|
'icon' => 'dashicons-dashboard'
|
|
),
|
|
array(
|
|
'title' => 'New Event',
|
|
'url' => home_url('/trainer/event/manage/'),
|
|
'icon' => 'dashicons-plus-alt'
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'title' => 'Certificates',
|
|
'url' => '#',
|
|
'icon' => 'dashicons-awards',
|
|
'children' => array(
|
|
array(
|
|
'title' => 'Reports',
|
|
'url' => home_url('/trainer/certificate-reports/'),
|
|
'icon' => 'dashicons-analytics'
|
|
),
|
|
array(
|
|
'title' => 'New Certificate',
|
|
'url' => home_url('/trainer/generate-certificates/'),
|
|
'icon' => 'dashicons-plus-alt'
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'title' => 'Customize',
|
|
'url' => '#',
|
|
'icon' => 'dashicons-admin-customizer',
|
|
'children' => array(
|
|
array(
|
|
'title' => 'Personal Profile',
|
|
'url' => home_url('/trainer/profile/'),
|
|
'icon' => 'dashicons-admin-users'
|
|
),
|
|
array(
|
|
'title' => 'Training Organizers',
|
|
'url' => home_url('/trainer/organizer/list/'),
|
|
'icon' => 'dashicons-groups',
|
|
'children' => array(
|
|
array(
|
|
'title' => 'Add New Organizer',
|
|
'url' => home_url('/trainer/organizer/manage/'),
|
|
'icon' => 'dashicons-plus-alt'
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'title' => 'Training Venues',
|
|
'url' => home_url('/trainer/venue/list/'),
|
|
'icon' => 'dashicons-location-alt',
|
|
'children' => array(
|
|
array(
|
|
'title' => 'Add New Venue',
|
|
'url' => home_url('/trainer/venue/manage/'),
|
|
'icon' => 'dashicons-plus-alt'
|
|
)
|
|
)
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'title' => 'Help',
|
|
'url' => home_url('/trainer/documentation/'),
|
|
'icon' => 'dashicons-sos'
|
|
)
|
|
);
|
|
|
|
// Add Master Dashboard for qualified users
|
|
if ($is_master) {
|
|
array_splice($menu, 0, 0, array(
|
|
array(
|
|
'title' => 'Master Dashboard',
|
|
'url' => home_url('/master-trainer/master-dashboard/'),
|
|
'icon' => 'dashicons-star-filled'
|
|
)
|
|
));
|
|
}
|
|
|
|
// Add logout as last item
|
|
$menu[] = array(
|
|
'title' => 'Logout',
|
|
'url' => wp_logout_url(home_url('/training-login/')),
|
|
'icon' => 'dashicons-exit'
|
|
);
|
|
|
|
return $menu;
|
|
}
|
|
|
|
/**
|
|
* Get master trainer menu structure
|
|
*/
|
|
private function get_master_menu_structure() {
|
|
$menu = array(
|
|
array(
|
|
'title' => 'Master Dashboard',
|
|
'url' => home_url('/master-trainer/master-dashboard/'),
|
|
'icon' => 'dashicons-dashboard'
|
|
),
|
|
array(
|
|
'title' => 'Trainer Dashboard',
|
|
'url' => home_url('/trainer/dashboard/'),
|
|
'icon' => 'dashicons-admin-home'
|
|
),
|
|
array(
|
|
'title' => 'Events',
|
|
'url' => '#',
|
|
'icon' => 'dashicons-calendar-alt',
|
|
'children' => array(
|
|
array(
|
|
'title' => 'All Events',
|
|
'url' => home_url('/master-trainer/events/'),
|
|
'icon' => 'dashicons-list-view'
|
|
),
|
|
array(
|
|
'title' => 'Create Event',
|
|
'url' => home_url('/trainer/create-event/'),
|
|
'icon' => 'dashicons-plus-alt'
|
|
),
|
|
array(
|
|
'title' => 'My Events',
|
|
'url' => home_url('/trainer/dashboard/'),
|
|
'icon' => 'dashicons-calendar'
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'title' => 'Certificates',
|
|
'url' => '#',
|
|
'icon' => 'dashicons-awards',
|
|
'children' => array(
|
|
array(
|
|
'title' => 'Certificate Reports',
|
|
'url' => home_url('/trainer/certificate-reports/'),
|
|
'icon' => 'dashicons-analytics'
|
|
),
|
|
array(
|
|
'title' => 'Generate Certificates',
|
|
'url' => home_url('/trainer/generate-certificates/'),
|
|
'icon' => 'dashicons-media-document'
|
|
)
|
|
)
|
|
),
|
|
array(
|
|
'title' => 'Profile',
|
|
'url' => home_url('/trainer/profile/'),
|
|
'icon' => 'dashicons-admin-users'
|
|
),
|
|
array(
|
|
'title' => 'Logout',
|
|
'url' => wp_logout_url(home_url('/training-login/')),
|
|
'icon' => 'dashicons-exit'
|
|
)
|
|
);
|
|
|
|
return $menu;
|
|
}
|
|
|
|
/**
|
|
* Render individual menu item
|
|
*/
|
|
private function render_menu_item($item, $level = 0) {
|
|
$has_children = !empty($item['children']);
|
|
$icon = !empty($item['icon']) ? '<span class="dashicons ' . esc_attr($item['icon']) . '"></span>' : '';
|
|
$classes = array('menu-item');
|
|
|
|
if ($has_children) {
|
|
$classes[] = 'has-children';
|
|
}
|
|
|
|
if ($level > 0) {
|
|
$classes[] = 'sub-menu-item';
|
|
$classes[] = 'level-' . $level;
|
|
}
|
|
|
|
echo '<li class="' . implode(' ', $classes) . '">';
|
|
|
|
if ($item['url'] === '#' && $has_children) {
|
|
echo '<span class="menu-toggle">' . $icon . esc_html($item['title']) . '<span class="dropdown-arrow">▼</span></span>';
|
|
} else {
|
|
echo '<a href="' . esc_url($item['url']) . '">' . $icon . esc_html($item['title']) . '</a>';
|
|
}
|
|
|
|
if ($has_children) {
|
|
echo '<ul class="sub-menu">';
|
|
foreach ($item['children'] as $child) {
|
|
$this->render_menu_item($child, $level + 1);
|
|
}
|
|
echo '</ul>';
|
|
}
|
|
|
|
echo '</li>';
|
|
}
|
|
|
|
/**
|
|
* Enqueue menu styles and scripts
|
|
*/
|
|
public function enqueue_menu_styles() {
|
|
if ($this->is_trainer_page() && $this->user_can_access_trainer_area()) {
|
|
wp_enqueue_style(
|
|
'hvac-menu-system',
|
|
HVAC_PLUGIN_URL . 'assets/css/hvac-menu-system.css',
|
|
array(),
|
|
HVAC_PLUGIN_VERSION
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'hvac-menu-system',
|
|
HVAC_PLUGIN_URL . 'assets/js/hvac-menu-system.js',
|
|
array('jquery'),
|
|
HVAC_PLUGIN_VERSION,
|
|
true
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add logout link to WordPress menu (if using wp_nav_menu)
|
|
*/
|
|
public function add_logout_to_menu($items, $args) {
|
|
if ($args->theme_location === 'hvac_trainer_menu' && $this->user_can_access_trainer_area()) {
|
|
$logout_link = '<li class="menu-item menu-item-logout"><a href="' . wp_logout_url(home_url('/training-login/')) . '"><span class="dashicons dashicons-exit"></span>Logout</a></li>';
|
|
$items .= $logout_link;
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
}
|
|
|
|
// Initialize
|
|
HVAC_Menu_System::instance(); |