fix: critical master dashboard rendering issues identified in zen code review
Address top 3 critical issues preventing dashboard content from rendering: 1. HTML Injection Fix (class-hvac-community-events.php:924-927): - Move error div from wp_head to wp_footer with proper styling - Prevent markup corruption that breaks content rendering - Add proper escaping with esc_html() 2. Remove Template Redundancy (class-hvac-community-events.php): - Remove force_master_dashboard_content() method and filter - Eliminate competing content injection mechanisms - Simplify to single template_include approach 3. Navigation System Integration (class-hvac-master-menu-system.php): - Align DOM IDs with existing JavaScript expectations - Change wrapper classes to match existing CSS hooks - Fix capability vs role filtering logic 4. Template Safety (page-master-dashboard.php): - Guard constant definition to prevent redefinition notices These fixes resolve zen GPT-5 identified issues: - [CRITICAL] HTML in wp_head breaking content display - [HIGH] Redundant template mechanisms causing conflicts - [HIGH] CSS/JS integration mismatches preventing navigation - [MEDIUM] Capability filtering using role names incorrectly Architecture improvements maintain security while fixing execution. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
9c2e8cdd3c
commit
2f9213e878
3 changed files with 30 additions and 24 deletions
|
|
@ -151,8 +151,6 @@ class HVAC_Community_Events {
|
||||||
// Template loading for custom pages
|
// Template loading for custom pages
|
||||||
add_filter('template_include', array($this, 'load_custom_templates'), 999);
|
add_filter('template_include', array($this, 'load_custom_templates'), 999);
|
||||||
|
|
||||||
// Force correct content on master dashboard
|
|
||||||
add_filter('the_content', array($this, 'force_master_dashboard_content'), 1);
|
|
||||||
|
|
||||||
// Force content on edit event page
|
// Force content on edit event page
|
||||||
add_filter('the_content', array($this, 'force_edit_event_content'), 1);
|
add_filter('the_content', array($this, 'force_edit_event_content'), 1);
|
||||||
|
|
@ -921,9 +919,9 @@ class HVAC_Community_Events {
|
||||||
HVAC_Logger::error("Template validation failed in load_custom_templates: {$validation}", 'Core');
|
HVAC_Logger::error("Template validation failed in load_custom_templates: {$validation}", 'Core');
|
||||||
|
|
||||||
// Display error or fallback template
|
// Display error or fallback template
|
||||||
add_action('wp_head', function() use ($validation) {
|
add_action('wp_footer', function() use ($validation) {
|
||||||
echo '<div class="hvac-error">There was a problem loading this page. ' .
|
echo '<div class="hvac-error" style="position:fixed;bottom:10px;left:10px;z-index:100000;background:#fff;padding:10px;border:1px solid #e0e0e0;">' .
|
||||||
'The administrator has been notified. Please try again later.</div>';
|
esc_html('There was a problem loading this page. The administrator has been notified. Please try again later.') . '</div>';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Either fall back to the standard WP template or use a simple error template
|
// Either fall back to the standard WP template or use a simple error template
|
||||||
|
|
@ -939,18 +937,6 @@ class HVAC_Community_Events {
|
||||||
return $template;
|
return $template;
|
||||||
} // End load_custom_templates
|
} // End load_custom_templates
|
||||||
|
|
||||||
/**
|
|
||||||
* Force master dashboard content on master dashboard page
|
|
||||||
*/
|
|
||||||
public function force_master_dashboard_content($content) {
|
|
||||||
// Only on master dashboard page
|
|
||||||
if (is_page('master-trainer/master-dashboard') && in_the_loop() && is_main_query()) {
|
|
||||||
// Return the master dashboard content
|
|
||||||
return $this->render_master_dashboard();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force edit event content on edit event page
|
* Force edit event content on edit event page
|
||||||
|
|
|
||||||
|
|
@ -82,17 +82,17 @@ class HVAC_Master_Menu_System {
|
||||||
|
|
||||||
$menu_items = $this->get_master_menu_structure();
|
$menu_items = $this->get_master_menu_structure();
|
||||||
|
|
||||||
echo '<div class="hvac-master-menu-wrapper">';
|
echo '<div class="hvac-trainer-menu-wrapper">';
|
||||||
echo '<nav class="hvac-master-nav" role="navigation">';
|
echo '<nav class="hvac-trainer-nav" role="navigation">';
|
||||||
|
|
||||||
// Add hamburger button for mobile
|
// Add hamburger button for mobile
|
||||||
echo '<button class="hvac-hamburger-menu" id="hvac-master-hamburger-menu" aria-label="Toggle menu" aria-expanded="false">';
|
echo '<button class="hvac-hamburger-menu" id="hvac-hamburger-menu" aria-label="Toggle menu" aria-expanded="false">';
|
||||||
echo '<span class="hvac-hamburger-line"></span>';
|
echo '<span class="hvac-hamburger-line"></span>';
|
||||||
echo '<span class="hvac-hamburger-line"></span>';
|
echo '<span class="hvac-hamburger-line"></span>';
|
||||||
echo '<span class="hvac-hamburger-line"></span>';
|
echo '<span class="hvac-hamburger-line"></span>';
|
||||||
echo '</button>';
|
echo '</button>';
|
||||||
|
|
||||||
echo '<ul class="hvac-master-menu" id="hvac-master-menu">';
|
echo '<ul class="hvac-trainer-menu" id="hvac-trainer-menu">';
|
||||||
|
|
||||||
foreach ($menu_items as $item) {
|
foreach ($menu_items as $item) {
|
||||||
$this->render_menu_item($item);
|
$this->render_menu_item($item);
|
||||||
|
|
@ -209,7 +209,17 @@ class HVAC_Master_Menu_System {
|
||||||
// Check if user has capability for this item
|
// Check if user has capability for this item
|
||||||
$required_cap = isset($item['cap']) ? $item['cap'] : 'hvac_master_trainer';
|
$required_cap = isset($item['cap']) ? $item['cap'] : 'hvac_master_trainer';
|
||||||
|
|
||||||
if (!current_user_can($required_cap)) {
|
// Handle role names vs capabilities properly
|
||||||
|
$user = wp_get_current_user();
|
||||||
|
$has_access = false;
|
||||||
|
|
||||||
|
if ($required_cap === 'hvac_master_trainer') {
|
||||||
|
$has_access = in_array('hvac_master_trainer', (array) $user->roles, true) || current_user_can('manage_options');
|
||||||
|
} else {
|
||||||
|
$has_access = current_user_can($required_cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$has_access) {
|
||||||
continue; // Skip this item
|
continue; // Skip this item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,7 +230,15 @@ class HVAC_Master_Menu_System {
|
||||||
foreach ($item['children'] as $child) {
|
foreach ($item['children'] as $child) {
|
||||||
$child_cap = isset($child['cap']) ? $child['cap'] : 'hvac_master_trainer';
|
$child_cap = isset($child['cap']) ? $child['cap'] : 'hvac_master_trainer';
|
||||||
|
|
||||||
if (current_user_can($child_cap)) {
|
// Handle role names vs capabilities properly for children too
|
||||||
|
$has_child_access = false;
|
||||||
|
if ($child_cap === 'hvac_master_trainer') {
|
||||||
|
$has_child_access = in_array('hvac_master_trainer', (array) $user->roles, true) || current_user_can('manage_options');
|
||||||
|
} else {
|
||||||
|
$has_child_access = current_user_can($child_cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($has_child_access) {
|
||||||
$filtered_children[] = $child;
|
$filtered_children[] = $child;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Define constant to indicate we are in a page template
|
// Define constant to indicate we are in a page template
|
||||||
define('HVAC_IN_PAGE_TEMPLATE', true);
|
if (!defined('HVAC_IN_PAGE_TEMPLATE')) {
|
||||||
|
define('HVAC_IN_PAGE_TEMPLATE', true);
|
||||||
|
}
|
||||||
|
|
||||||
get_header();
|
get_header();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue