feat: Add admin and master trainer support to navigation system
Enhanced navigation system to support multiple user types: ✅ USER TYPE SUPPORT: - HVAC Trainers: Full navigation access - HVAC Master Trainers: Full navigation + Master Dashboard link - WordPress Admins: Full navigation + Master Dashboard link ✅ NAVIGATION UPDATES: - Added Master Dashboard as main menu item for masters/admins - Updated capability checks to allow admin access to all items - Created user_can_access_item() helper method for flexible permissions - Admins can now access all trainer functionality ✅ MASTER DASHBOARD INTEGRATION: - Master Dashboard link prominently displayed for qualified users - Maintains existing Master Trainer submenu structure - Clean separation between regular trainer and master trainer features ✅ CAPABILITY SYSTEM: - hvac_trainer: Basic trainer navigation - hvac_master_trainer: Enhanced navigation with master features - manage_options: Full administrative access to all features Navigation now properly displays for WordPress administrators, providing full access to the HVAC trainer system while maintaining proper role-based permissions. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c4ec1818b5
commit
5a302f2312
1 changed files with 34 additions and 5 deletions
|
|
@ -57,6 +57,7 @@ class HVAC_Trainer_Navigation {
|
||||||
private function get_menu_items() {
|
private function get_menu_items() {
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
$is_master = in_array('hvac_master_trainer', $user->roles);
|
$is_master = in_array('hvac_master_trainer', $user->roles);
|
||||||
|
$is_admin = current_user_can('manage_options');
|
||||||
|
|
||||||
$menu_items = array(
|
$menu_items = array(
|
||||||
'dashboard' => array(
|
'dashboard' => array(
|
||||||
|
|
@ -149,8 +150,18 @@ class HVAC_Trainer_Navigation {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add master trainer items if applicable
|
// Add Master Dashboard as main menu item for master trainers and admins
|
||||||
if ($is_master) {
|
if ($is_master || $is_admin) {
|
||||||
|
$menu_items['master-dashboard'] = array(
|
||||||
|
'label' => 'Master Dashboard',
|
||||||
|
'url' => '/master-trainer/master-dashboard/',
|
||||||
|
'icon' => 'dashicons-star-filled',
|
||||||
|
'capability' => 'hvac_master_trainer'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add master trainer items if applicable (for master trainers or WordPress admins)
|
||||||
|
if ($is_master || $is_admin) {
|
||||||
$menu_items['master'] = array(
|
$menu_items['master'] = array(
|
||||||
'label' => 'Master Trainer',
|
'label' => 'Master Trainer',
|
||||||
'url' => '#',
|
'url' => '#',
|
||||||
|
|
@ -179,6 +190,19 @@ class HVAC_Trainer_Navigation {
|
||||||
return apply_filters('hvac_trainer_menu_items', $menu_items);
|
return apply_filters('hvac_trainer_menu_items', $menu_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if user can access item (admins can access everything)
|
||||||
|
*/
|
||||||
|
private function user_can_access_item($capability) {
|
||||||
|
// WordPress admins can access everything
|
||||||
|
if (current_user_can('manage_options')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise check the specific capability
|
||||||
|
return current_user_can($capability);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get current page identifier
|
* Get current page identifier
|
||||||
*/
|
*/
|
||||||
|
|
@ -233,7 +257,12 @@ class HVAC_Trainer_Navigation {
|
||||||
* Render navigation shortcode
|
* Render navigation shortcode
|
||||||
*/
|
*/
|
||||||
public function render_navigation($atts = array()) {
|
public function render_navigation($atts = array()) {
|
||||||
if (!is_user_logged_in() || !current_user_can('hvac_trainer')) {
|
if (!is_user_logged_in()) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show navigation for trainers, master trainers, or WordPress admins
|
||||||
|
if (!current_user_can('hvac_trainer') && !current_user_can('hvac_master_trainer') && !current_user_can('manage_options')) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -263,8 +292,8 @@ class HVAC_Trainer_Navigation {
|
||||||
echo '<ul class="hvac-nav-menu">';
|
echo '<ul class="hvac-nav-menu">';
|
||||||
|
|
||||||
foreach ($menu_items as $item_id => $item) {
|
foreach ($menu_items as $item_id => $item) {
|
||||||
// Check capability
|
// Check capability (allow admins to access everything)
|
||||||
if (isset($item['capability']) && !current_user_can($item['capability'])) {
|
if (isset($item['capability']) && !$this->user_can_access_item($item['capability'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue