fix: Resolve Master Trainer permissions and navigation issues
- Fix AJAX 400 error on master dashboard by adding missing handler - Fix Google Sheets folder verification JSON parse error - Fix certificate reports permission check for master trainers - Update all navigation links to use new hierarchical URL structure - Remove 11 duplicate/legacy WordPress pages - Fix Google Sheets page redirect loop - Update profile edit link behavior - Document all URL mapping changes and fixes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
587773b56b
commit
58626ffc16
2 changed files with 321 additions and 0 deletions
154
wordpress-dev/MASTER-TRAINER-FIXES-2025-06-17.md
Normal file
154
wordpress-dev/MASTER-TRAINER-FIXES-2025-06-17.md
Normal file
|
|
@ -0,0 +1,154 @@
|
||||||
|
# Master Trainer Permission & Navigation Fixes
|
||||||
|
**Date**: June 17, 2025
|
||||||
|
**Developer**: Ben Reed (ben@tealmaker.com)
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
This document summarizes the fixes applied to resolve Master Trainer permission issues, AJAX errors, and navigation problems reported by the user.
|
||||||
|
|
||||||
|
## Issues Fixed
|
||||||
|
|
||||||
|
### 1. Master Dashboard AJAX 400 Error ✅
|
||||||
|
**Problem**: Master dashboard was making AJAX call to `hvac_master_dashboard_events` but no handler existed.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Added missing AJAX handler registration in `includes/class-hvac-community-events.php`
|
||||||
|
- Added `ajax_master_dashboard_events()` method to handle the AJAX request
|
||||||
|
- The handler properly checks permissions and returns events table data
|
||||||
|
|
||||||
|
**Files Modified**:
|
||||||
|
- `includes/class-hvac-community-events.php`
|
||||||
|
|
||||||
|
### 2. Google Sheets Folder Verification JSON Error ✅
|
||||||
|
**Problem**: AJAX call returned "JSON.parse: unexpected character" error.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Fixed incorrect file path in `ajax_verify_folder_structure()` method
|
||||||
|
- Added error handling and output buffering
|
||||||
|
- Temporarily returns mock data until Google Sheets auth is configured
|
||||||
|
- Prevents PHP errors from breaking JSON response
|
||||||
|
|
||||||
|
**Files Modified**:
|
||||||
|
- `includes/google-sheets/class-google-sheets-admin.php`
|
||||||
|
|
||||||
|
### 3. Certificate Reports Permission Error ✅
|
||||||
|
**Problem**: Master trainers saw "You do not have permission to view certificate reports."
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Fixed capability check from `current_user_can('hvac_trainer')` to `current_user_can('manage_hvac_events')`
|
||||||
|
- Master trainers have the `manage_hvac_events` capability
|
||||||
|
|
||||||
|
**Files Modified**:
|
||||||
|
- `includes/class-hvac-community-events.php`
|
||||||
|
|
||||||
|
### 4. Navigation Links to Old URLs ✅
|
||||||
|
**Problem**: Links throughout the plugin pointed to old URLs like `/hvac-dashboard/` instead of new hierarchical URLs.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Updated 44+ URL references in template files
|
||||||
|
- Updated all URLs in includes directory
|
||||||
|
- Fixed hardcoded links
|
||||||
|
- Implemented proper URL mapping:
|
||||||
|
- `/hvac-dashboard/` → `/trainer/dashboard/`
|
||||||
|
- `/certificate-reports/` → `/trainer/certificate-reports/`
|
||||||
|
- `/generate-certificates/` → `/trainer/generate-certificates/`
|
||||||
|
- And many more...
|
||||||
|
|
||||||
|
**Files Modified**:
|
||||||
|
- All template files in `templates/` directory
|
||||||
|
- Multiple files in `includes/` directory
|
||||||
|
- `clear-test-certificates.php`
|
||||||
|
|
||||||
|
### 5. Duplicate/Legacy WordPress Pages ✅
|
||||||
|
**Problem**: Multiple duplicate pages existed with old slugs causing confusion.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Deleted 11 duplicate pages (IDs: 5297, 5298, 5299, 5300, 5502, 5503, 5504, 5505, 5517, 5518, 5519)
|
||||||
|
- Kept only the properly structured hierarchical pages
|
||||||
|
- Legacy redirect system handles old URLs automatically
|
||||||
|
|
||||||
|
### 6. Google Sheets Redirect Loop ✅
|
||||||
|
**Problem**: `/master-trainer/google-sheets/` was causing infinite redirect loop.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Added redirect loop prevention in `hvac_ce_handle_legacy_redirects()` function
|
||||||
|
- Checks if already on target path before redirecting
|
||||||
|
- Fixed OAuth callback redirect URLs
|
||||||
|
|
||||||
|
**Files Modified**:
|
||||||
|
- `hvac-community-events.php`
|
||||||
|
- `includes/google-sheets/class-google-sheets-auth.php`
|
||||||
|
|
||||||
|
### 7. Profile Edit Link ✅
|
||||||
|
**Problem**: "Edit Profile" button opened wp-admin in new tab.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Removed `target="_blank"` from edit profile link
|
||||||
|
- Now opens in same tab for better UX
|
||||||
|
|
||||||
|
**Files Modified**:
|
||||||
|
- `templates/template-trainer-profile.php`
|
||||||
|
|
||||||
|
### 8. Master Dashboard Template Rendering ✅
|
||||||
|
**Problem**: Master dashboard had jQuery undefined errors and Quirks Mode.
|
||||||
|
|
||||||
|
**Solution**:
|
||||||
|
- Added missing `get_header()` call for authenticated users
|
||||||
|
- Fixed template structure to include proper WordPress header
|
||||||
|
|
||||||
|
**Files Modified**:
|
||||||
|
- `templates/template-hvac-master-dashboard.php`
|
||||||
|
|
||||||
|
## Technical Details
|
||||||
|
|
||||||
|
### AJAX Handler Implementation
|
||||||
|
```php
|
||||||
|
public function ajax_master_dashboard_events() {
|
||||||
|
check_ajax_referer('hvac_master_dashboard_nonce', 'nonce');
|
||||||
|
|
||||||
|
if (!current_user_can('view_master_dashboard')) {
|
||||||
|
wp_die('Insufficient permissions');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load master dashboard data class
|
||||||
|
if (!class_exists('HVAC_Master_Dashboard_Data')) {
|
||||||
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-master-dashboard-data.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
$dashboard_data = new HVAC_Master_Dashboard_Data();
|
||||||
|
$data = $dashboard_data->get_events_table_data($args);
|
||||||
|
|
||||||
|
wp_send_json_success($data);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Redirect Loop Prevention
|
||||||
|
```php
|
||||||
|
// Get current URL path to prevent redirect loops
|
||||||
|
$current_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
|
||||||
|
$target_path = $legacy_redirects[$current_slug];
|
||||||
|
|
||||||
|
// Skip redirect if we are already on the target path
|
||||||
|
if ($current_path === $target_path) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing Recommendations
|
||||||
|
|
||||||
|
1. **Master Dashboard**: Verify events table loads without AJAX errors
|
||||||
|
2. **Google Sheets**: Check that folder verification shows appropriate message
|
||||||
|
3. **Certificate Reports**: Confirm master trainers can access reports
|
||||||
|
4. **Navigation**: Test all navigation links go to correct hierarchical URLs
|
||||||
|
5. **Legacy URLs**: Verify old URLs redirect properly to new ones
|
||||||
|
|
||||||
|
## Pending Issues
|
||||||
|
|
||||||
|
1. **Trainer Documentation Login**: Still showing "Please log in to access the documentation" - may need further investigation
|
||||||
|
2. **Google Sheets Authentication**: Full folder verification will work once OAuth is configured
|
||||||
|
|
||||||
|
## Deployment Notes
|
||||||
|
|
||||||
|
- All changes are live on staging server
|
||||||
|
- WordPress cache has been flushed
|
||||||
|
- No database schema changes required
|
||||||
|
- Backward compatibility maintained through redirect system
|
||||||
167
wordpress-dev/URL_MAPPING.md
Normal file
167
wordpress-dev/URL_MAPPING.md
Normal file
|
|
@ -0,0 +1,167 @@
|
||||||
|
# HVAC Community Events Plugin - URL Structure Migration
|
||||||
|
|
||||||
|
## URL Mapping - Old to New
|
||||||
|
|
||||||
|
| Current URL | New URL | Priority | Status |
|
||||||
|
|-------------|---------|----------|--------|
|
||||||
|
| `/community-login/` | `/training-login/` | HIGH | ✅ Complete |
|
||||||
|
| `/trainer-registration/` | `/trainer/registration/` | HIGH | ✅ Complete |
|
||||||
|
| `/hvac-dashboard/` | `/trainer/dashboard/` | HIGH | ✅ Complete |
|
||||||
|
| `/master-dashboard/` | `/master-trainer/dashboard/` | HIGH | ✅ Complete |
|
||||||
|
| `/manage-event/` | `/trainer/event/manage/` | HIGH | ✅ Complete |
|
||||||
|
| `/event-summary/` | `/trainer/event/summary/` | MEDIUM | ✅ Complete |
|
||||||
|
| `/trainer-profile/` | `/trainer/my-profile/` | HIGH | ✅ Complete |
|
||||||
|
| `/attendee-profile/` | `/trainer/attendee-profile/` | LOW | ✅ Complete |
|
||||||
|
| `/email-attendees/` | `/trainer/email-attendees/` | MEDIUM | ✅ Complete |
|
||||||
|
| `/communication-templates/` | `/trainer/communication-templates/` | MEDIUM | ✅ Complete |
|
||||||
|
| `/communication-schedules/` | `/trainer/communication-schedules/` | MEDIUM | ✅ Complete |
|
||||||
|
| `/generate-certificates/` | `/trainer/generate-certificates/` | MEDIUM | ✅ Complete |
|
||||||
|
| `/certificate-reports/` | `/trainer/certificate-reports/` | MEDIUM | ✅ Complete |
|
||||||
|
| `/google-sheets/` | `/master-trainer/google-sheets/` | MEDIUM | ✅ Complete |
|
||||||
|
| `/hvac-documentation/` | `/trainer/documentation/` | LOW | ✅ Complete |
|
||||||
|
| `/certificate-fix/` | `/master-trainer/certificate-fix/` | HIGH | ✅ Complete |
|
||||||
|
|
||||||
|
## References to Update
|
||||||
|
|
||||||
|
### High Priority Files (Core Navigation/Authentication)
|
||||||
|
1. **Main Plugin File** (`hvac-community-events.php`)
|
||||||
|
- Page creation array (lines 46-117)
|
||||||
|
- Asset loading checks (lines 260-266, 342, 358, 374, 433)
|
||||||
|
|
||||||
|
2. **Login Handler** (`includes/community/class-login-handler.php`)
|
||||||
|
- Redirect URLs (lines 143, 175, 182, 202, 209, 214)
|
||||||
|
|
||||||
|
3. **HVAC Community Events Class** (`includes/class-hvac-community-events.php`)
|
||||||
|
- Authentication redirects (lines 154, 166, 178, 188, 191, 198, 212, 219)
|
||||||
|
|
||||||
|
4. **Dashboard Templates**
|
||||||
|
- `templates/template-hvac-dashboard.php`
|
||||||
|
- `templates/template-hvac-master-dashboard.php`
|
||||||
|
|
||||||
|
### Medium Priority Files (Navigation/Features)
|
||||||
|
5. **Dashboard Class** (`includes/class-hvac-dashboard.php`)
|
||||||
|
6. **Manage Event Class** (`includes/class-hvac-manage-event.php`)
|
||||||
|
7. **Registration Class** (`includes/class-hvac-registration.php`)
|
||||||
|
8. **Settings Class** (`includes/class-hvac-settings.php`)
|
||||||
|
9. **Help System** (`includes/class-hvac-help-system.php`)
|
||||||
|
|
||||||
|
### Low Priority Files (Templates/Tests)
|
||||||
|
10. **Certificate Templates** (multiple files)
|
||||||
|
11. **Profile Templates**
|
||||||
|
12. **Test Files** (50+ files in `/bin/` and root)
|
||||||
|
|
||||||
|
## Implementation Strategy
|
||||||
|
|
||||||
|
### Phase 1: Core Structure (HIGH Priority)
|
||||||
|
1. Update page creation code in main plugin file
|
||||||
|
2. Create URL mapping helper functions
|
||||||
|
3. Update login redirection logic
|
||||||
|
4. Add backward compatibility redirects
|
||||||
|
|
||||||
|
### Phase 2: Navigation (HIGH Priority)
|
||||||
|
5. Update dashboard navigation links
|
||||||
|
6. Update authentication redirect URLs
|
||||||
|
7. Update template hardcoded links
|
||||||
|
|
||||||
|
### Phase 3: Features (MEDIUM Priority)
|
||||||
|
8. Update shortcode references
|
||||||
|
9. Update help system links
|
||||||
|
10. Update asset loading checks
|
||||||
|
|
||||||
|
### Phase 4: Testing & Documentation (LOW Priority)
|
||||||
|
11. Update test files
|
||||||
|
12. Update documentation
|
||||||
|
13. Comprehensive testing
|
||||||
|
|
||||||
|
## Backward Compatibility Plan
|
||||||
|
|
||||||
|
### 301 Redirects Required
|
||||||
|
All old URLs must redirect to new URLs using WordPress redirect functions:
|
||||||
|
|
||||||
|
```php
|
||||||
|
// Example redirect mapping
|
||||||
|
$legacy_redirects = [
|
||||||
|
'community-login' => 'training-login',
|
||||||
|
'hvac-dashboard' => 'trainer/dashboard',
|
||||||
|
'master-dashboard' => 'master-trainer/dashboard',
|
||||||
|
'manage-event' => 'trainer/event/manage',
|
||||||
|
'trainer-profile' => 'trainer/my-profile',
|
||||||
|
'certificate-fix' => 'master-trainer/certificate-fix',
|
||||||
|
// ... etc
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
### Implementation Notes
|
||||||
|
- Use WordPress `wp_redirect()` with 301 status
|
||||||
|
- Preserve query parameters during redirects
|
||||||
|
- Implement in `template_redirect` hook
|
||||||
|
- Log redirects for monitoring
|
||||||
|
|
||||||
|
## Security Considerations
|
||||||
|
|
||||||
|
### Access Control Updates
|
||||||
|
- **Certificate Fix**: Move to `/master-trainer/` hierarchy requires permission check updates
|
||||||
|
- **Role-based URLs**: Ensure URL structure matches permission model
|
||||||
|
- **Capability Checks**: Update template redirect logic for new URLs
|
||||||
|
|
||||||
|
## Testing Checklist
|
||||||
|
|
||||||
|
### Functional Testing
|
||||||
|
- [ ] All new URLs load correctly
|
||||||
|
- [ ] All old URLs redirect properly
|
||||||
|
- [ ] Login redirects to correct dashboard
|
||||||
|
- [ ] Navigation between trainer/master trainer dashboards works
|
||||||
|
- [ ] Certificate fix page restricted to master trainers only
|
||||||
|
|
||||||
|
### Technical Testing
|
||||||
|
- [ ] No 404 errors on any URL
|
||||||
|
- [ ] Query parameters preserved in redirects
|
||||||
|
- [ ] Assets load correctly on all pages
|
||||||
|
- [ ] Help system links work
|
||||||
|
- [ ] Test suite passes with new URLs
|
||||||
|
|
||||||
|
## Deployment Plan
|
||||||
|
|
||||||
|
### Pre-deployment
|
||||||
|
1. Create database backup
|
||||||
|
2. Test in staging environment
|
||||||
|
3. Verify all redirects work
|
||||||
|
4. Update user documentation
|
||||||
|
|
||||||
|
### Deployment
|
||||||
|
1. Deploy plugin with URL changes
|
||||||
|
2. Clear all caches
|
||||||
|
3. Test key user journeys
|
||||||
|
4. Monitor for 404 errors
|
||||||
|
|
||||||
|
### Post-deployment
|
||||||
|
1. Monitor redirect usage
|
||||||
|
2. Update external documentation
|
||||||
|
3. Communicate changes to users
|
||||||
|
4. Plan to remove redirects after transition period
|
||||||
|
|
||||||
|
## Files to Modify
|
||||||
|
|
||||||
|
### Core Files (16 files)
|
||||||
|
- `hvac-community-events.php`
|
||||||
|
- `includes/class-hvac-community-events.php`
|
||||||
|
- `includes/community/class-login-handler.php`
|
||||||
|
- `includes/class-hvac-dashboard.php`
|
||||||
|
- `includes/class-hvac-manage-event.php`
|
||||||
|
- `includes/class-hvac-registration.php`
|
||||||
|
- `includes/class-hvac-settings.php`
|
||||||
|
- `includes/class-hvac-help-system.php`
|
||||||
|
- `templates/template-hvac-dashboard.php`
|
||||||
|
- `templates/template-hvac-master-dashboard.php`
|
||||||
|
- `templates/template-trainer-profile.php`
|
||||||
|
- `templates/template-event-summary.php`
|
||||||
|
- Multiple certificate template files
|
||||||
|
- Test files (50+ files)
|
||||||
|
|
||||||
|
### Estimated Effort
|
||||||
|
- **Planning/Analysis**: ✅ Complete
|
||||||
|
- **Core Implementation**: 4-6 hours
|
||||||
|
- **Template Updates**: 2-3 hours
|
||||||
|
- **Testing**: 2-3 hours
|
||||||
|
- **Documentation**: 1-2 hours
|
||||||
|
- **Total**: 10-15 hours
|
||||||
Loading…
Reference in a new issue