diff --git a/includes/class-hvac-community-events.php b/includes/class-hvac-community-events.php
index f50848b7..4c31eb10 100644
--- a/includes/class-hvac-community-events.php
+++ b/includes/class-hvac-community-events.php
@@ -572,8 +572,9 @@ class HVAC_Community_Events {
return '
Please log in to view the master dashboard.
';
}
- // Check if user has master dashboard permissions - include administrator
- if (!current_user_can('view_master_dashboard') && !current_user_can('view_all_trainer_data') && !current_user_can('administrator')) {
+ // Check if user has master dashboard permissions - check roles instead of capabilities
+ $user = wp_get_current_user();
+ if (!in_array('hvac_master_trainer', $user->roles) && !current_user_can('manage_options')) {
return 'You do not have permission to view the master dashboard. This dashboard is only available to Master Trainers and Administrators.
';
}
@@ -833,14 +834,9 @@ class HVAC_Community_Events {
$custom_template = HVAC_PLUGIN_DIR . 'templates/page-trainer-dashboard.php';
}
- // For master dashboard, check if page has custom template
+ // For master dashboard, force our template regardless of WordPress template assignment
if (is_page('master-trainer/master-dashboard')) {
- global $post;
- $page_template = get_post_meta($post->ID, '_wp_page_template', true);
- if ($page_template && $page_template !== 'default') {
- // Let WordPress handle the page template
- return $template;
- }
+ $custom_template = HVAC_PLUGIN_DIR . 'templates/page-master-dashboard.php';
}
// Check for google-sheets page
diff --git a/includes/class-hvac-master-menu-system.php b/includes/class-hvac-master-menu-system.php
new file mode 100644
index 00000000..05fdb1a2
--- /dev/null
+++ b/includes/class-hvac-master-menu-system.php
@@ -0,0 +1,342 @@
+roles) && !current_user_can('manage_options')) {
+ return;
+ }
+
+ $menu_items = $this->get_master_menu_structure();
+
+ echo '';
+ }
+
+ /**
+ * Get master trainer menu structure
+ * Simplified to 5 essential items following UX best practices
+ */
+ private function get_master_menu_structure() {
+ // Define simplified menu structure (5 primary items max)
+ $menu = array(
+ // Dashboard - Primary landing page
+ array(
+ 'title' => esc_html__('Dashboard', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/master-dashboard/'),
+ 'icon' => 'dashicons-dashboard',
+ 'cap' => 'hvac_master_trainer'
+ ),
+
+ // Trainers - Core management function
+ array(
+ 'title' => esc_html__('Trainers', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/trainers/'),
+ 'icon' => 'dashicons-groups',
+ 'cap' => 'hvac_master_trainer',
+ 'children' => array(
+ array(
+ 'title' => esc_html__('All Trainers', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/trainers/'),
+ 'icon' => 'dashicons-list-view',
+ 'cap' => 'hvac_master_trainer'
+ ),
+ array(
+ 'title' => esc_html__('Pending Approvals', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/pending-approvals/'),
+ 'icon' => 'dashicons-clock',
+ 'cap' => 'approve_trainers'
+ )
+ )
+ ),
+
+ // Events - Aggregate event management
+ array(
+ 'title' => esc_html__('Events', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/events/'),
+ 'icon' => 'dashicons-calendar-alt',
+ 'cap' => 'view_all_events'
+ ),
+
+ // Tools - Administrative functions
+ array(
+ 'title' => esc_html__('Tools', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/communication-templates/'),
+ 'icon' => 'dashicons-admin-tools',
+ 'cap' => 'manage_communication_templates',
+ 'children' => array(
+ array(
+ 'title' => esc_html__('Communication Templates', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/communication-templates/'),
+ 'icon' => 'dashicons-email',
+ 'cap' => 'manage_communication_templates'
+ ),
+ array(
+ 'title' => esc_html__('Announcements', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/announcements/'),
+ 'icon' => 'dashicons-megaphone',
+ 'cap' => 'manage_announcements'
+ ),
+ array(
+ 'title' => esc_html__('Import/Export', 'hvac-community-events'),
+ 'url' => home_url('/master-trainer/import-export/'),
+ 'icon' => 'dashicons-database-import',
+ 'cap' => 'import_export_data'
+ )
+ )
+ ),
+
+ // Help - Documentation
+ array(
+ 'title' => esc_html__('Help', 'hvac-community-events'),
+ 'url' => home_url('/trainer/documentation/'),
+ 'icon' => 'dashicons-editor-help',
+ 'cap' => 'read',
+ 'class' => 'hvac-help-menu-item'
+ )
+ );
+
+ // Allow other plugins to modify menu
+ $menu = apply_filters('hvac_master_menu_items', $menu);
+
+ // Filter menu items by user capabilities
+ $menu = $this->filter_menu_by_capabilities($menu);
+
+ return $menu;
+ }
+
+ /**
+ * Filter menu items by user capabilities
+ * Removes items the current user cannot access
+ *
+ * @param array $menu_items Menu items array
+ * @return array Filtered menu items
+ */
+ private function filter_menu_by_capabilities($menu_items) {
+ $filtered_menu = array();
+
+ foreach ($menu_items as $item) {
+ // Check if user has capability for this item
+ $required_cap = isset($item['cap']) ? $item['cap'] : 'hvac_master_trainer';
+
+ if (!current_user_can($required_cap)) {
+ continue; // Skip this item
+ }
+
+ // Filter children if they exist
+ if (isset($item['children']) && is_array($item['children'])) {
+ $filtered_children = array();
+
+ foreach ($item['children'] as $child) {
+ $child_cap = isset($child['cap']) ? $child['cap'] : 'hvac_master_trainer';
+
+ if (current_user_can($child_cap)) {
+ $filtered_children[] = $child;
+ }
+ }
+
+ // Only include parent if it has accessible children or is directly accessible
+ if (!empty($filtered_children)) {
+ $item['children'] = $filtered_children;
+ $filtered_menu[] = $item;
+ } elseif (!isset($item['children']) || empty($item['children'])) {
+ // Include parent items without children
+ $filtered_menu[] = $item;
+ }
+ } else {
+ // Include items without children
+ $filtered_menu[] = $item;
+ }
+ }
+
+ return $filtered_menu;
+ }
+
+ /**
+ * Render a single menu item
+ *
+ * @param array $item Menu item configuration
+ */
+ private function render_menu_item($item) {
+ $has_children = !empty($item['children']);
+ $current_url = $_SERVER['REQUEST_URI'];
+
+ // Check if this item or any of its children are active
+ $is_active = $this->is_menu_item_active($item, $current_url);
+
+ $li_classes = array('menu-item');
+ if ($is_active) {
+ $li_classes[] = 'current-menu-item';
+ }
+ if ($has_children) {
+ $li_classes[] = 'has-children';
+ }
+ if (!empty($item['class'])) {
+ $li_classes[] = $item['class'];
+ }
+
+ echo '
+
+
Access Denied
+
You do not have permission to access this page.
+
If you believe this is an error, please contact an administrator.
+
Return to Home
+
+
+ render_master_menu();
+}
+
+// Render breadcrumbs
+if (class_exists('HVAC_Breadcrumbs')) {
+ HVAC_Breadcrumbs::render();
+}
+
+echo '';
+echo '
';
+
+// Render the master dashboard content directly (bypassing shortcode processing)
+include HVAC_PLUGIN_DIR . 'templates/template-hvac-master-dashboard.php';
+
+echo '
'; // .container
+echo '
'; // .hvac-page-wrapper
+
get_footer();