From b7dfde141f96612eca1351dd250599a1da609f4d Mon Sep 17 00:00:00 2001 From: bengizmo Date: Mon, 16 Jun 2025 12:39:29 -0300 Subject: [PATCH] feat: Improve dashboard navigation for Master Trainers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Master Dashboard button to trainer dashboard for users with master trainer capabilities - Change "Your Dashboard" to "Trainer Dashboard" in master dashboard for clearer navigation - Update login redirection logic to prioritize Master Trainers (redirect to master-dashboard first) - Enhance cross-navigation between dashboards based on user permissions Files modified: - templates/template-hvac-dashboard.php: Added conditional Master Dashboard button - templates/template-hvac-master-dashboard.php: Updated button text for clarity - includes/community/class-login-handler.php: Enhanced login redirect logic 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../community/class-login-handler.php | 21 ++++++++++++++----- .../templates/template-hvac-dashboard.php | 6 ++++++ .../template-hvac-master-dashboard.php | 2 +- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/community/class-login-handler.php b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/community/class-login-handler.php index ab58f906..13858ce5 100644 --- a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/community/class-login-handler.php +++ b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/community/class-login-handler.php @@ -169,9 +169,15 @@ class Login_Handler { public function custom_login_redirect( $redirect_to, $requested_redirect_to, $user ) { // Check if login was successful and user is not an error object if ( $user && ! is_wp_error( $user ) ) { + // Check if the user has Master Trainer capabilities - redirect to Master Dashboard first + if ( user_can( $user, 'view_master_dashboard' ) || user_can( $user, 'view_all_trainer_data' ) ) { + // Redirect Master Trainers to the Master Dashboard + $master_dashboard_url = home_url( '/master-dashboard/' ); + return $master_dashboard_url; + } // Check if the user has the 'hvac_trainer' role - if ( in_array( 'hvac_trainer', (array) $user->roles ) ) { - // Redirect HVAC trainers to their dashboard + elseif ( in_array( 'hvac_trainer', (array) $user->roles ) ) { + // Redirect regular HVAC trainers to their dashboard // Assumes dashboard page slug is 'hvac-dashboard'. Adjust if needed. $dashboard_url = home_url( '/hvac-dashboard/' ); return $dashboard_url; @@ -197,9 +203,14 @@ class Login_Handler { // Get current user $user = wp_get_current_user(); - // Redirect based on user role/capabilities - if ( in_array( 'hvac_trainer', (array) $user->roles ) || current_user_can( 'view_hvac_dashboard' ) ) { - // HVAC trainers go to their dashboard + // Redirect based on user role/capabilities - prioritize Master Trainers + if ( current_user_can( 'view_master_dashboard' ) || current_user_can( 'view_all_trainer_data' ) ) { + // Master Trainers go to the Master Dashboard + $master_dashboard_url = home_url( '/master-dashboard/' ); + wp_safe_redirect( $master_dashboard_url ); + exit; + } elseif ( in_array( 'hvac_trainer', (array) $user->roles ) || current_user_can( 'view_hvac_dashboard' ) ) { + // Regular HVAC trainers go to their dashboard $dashboard_url = home_url( '/hvac-dashboard/' ); wp_safe_redirect( $dashboard_url ); exit; diff --git a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-dashboard.php b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-dashboard.php index d6215329..97d52692 100644 --- a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-dashboard.php +++ b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-dashboard.php @@ -123,6 +123,12 @@ get_header(); // Use theme's header 'View Profile', 'Update your professional credentials, business information, and training specialties' ); ?> + + Master Dashboard', + 'Access the Master Trainer Dashboard to view system-wide analytics and manage all trainers' + ); ?> + Help Logout diff --git a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-master-dashboard.php b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-master-dashboard.php index 8b294f4e..727a8c37 100644 --- a/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-master-dashboard.php +++ b/wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/templates/template-hvac-master-dashboard.php @@ -143,7 +143,7 @@ if ( isset( $_GET['error'] ) && $_GET['error'] === 'access_denied' ) { Templates - Your Dashboard + Trainer Dashboard Logout