upskill-event-manager/wordpress-dev/MASTER-TRAINER-FIXES-2025-06-17.md
bengizmo 58626ffc16 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>
2025-06-17 12:15:09 -03:00

5.3 KiB

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

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

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

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

// 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