diff --git a/includes/class-hvac-route-manager.php b/includes/class-hvac-route-manager.php index f22c62f4..063e50aa 100644 --- a/includes/class-hvac-route-manager.php +++ b/includes/class-hvac-route-manager.php @@ -136,16 +136,10 @@ class HVAC_Route_Manager { } // Add rewrite rules for hierarchical URLs + // IMPORTANT: Only add rules for pages that don't exist as actual WordPress pages $hierarchical_rules = array( - // Trainer pages - 'trainer/?$' => 'index.php?hvac_route=trainer', - 'trainer/([^/]+)/?$' => 'index.php?hvac_route=trainer&hvac_page=$matches[1]', - 'trainer/([^/]+)/([^/]+)/?$' => 'index.php?hvac_route=trainer&hvac_page=$matches[1]&hvac_subpage=$matches[2]', - - // Master trainer pages - 'master-trainer/?$' => 'index.php?hvac_route=master-trainer', - 'master-trainer/([^/]+)/?$' => 'index.php?hvac_route=master-trainer&hvac_page=$matches[1]', - 'master-trainer/([^/]+)/([^/]+)/?$' => 'index.php?hvac_route=master-trainer&hvac_page=$matches[1]&hvac_subpage=$matches[2]', + // Only add rules for event manage subpages + 'trainer/event/([^/]+)/?$' => 'index.php?hvac_route=trainer&hvac_page=event&hvac_subpage=$matches[1]', ); foreach ($hierarchical_rules as $regex => $redirect) { diff --git a/scripts/disable-conflicting-rewrites.sh b/scripts/disable-conflicting-rewrites.sh new file mode 100755 index 00000000..d4e550b4 --- /dev/null +++ b/scripts/disable-conflicting-rewrites.sh @@ -0,0 +1,97 @@ +#!/bin/bash + +echo "=== Disabling Conflicting Rewrite Rules ===" + +# SSH into staging and comment out the problematic rules +ssh roodev@146.190.76.204 << 'EOF' +cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html + +# Create a temporary fix by removing the conflicting rewrite rules +wp eval ' +// Remove the trainer route rules that conflict with actual pages +remove_action("init", array(HVAC_Route_Manager::instance(), "register_rewrite_rules"), 5); + +// Flush rewrite rules to clear them +flush_rewrite_rules(); +' + +# Now let's create a more targeted approach +echo "Creating targeted rewrite fix..." + +# Create a mu-plugin to handle this properly +mkdir -p wp-content/mu-plugins + +cat > wp-content/mu-plugins/hvac-fix-page-routing.php << 'PHP' +rules; + + // Remove rules that conflict with actual pages + $conflicting_patterns = array( + 'trainer/([^/]+)/?$', + 'master-trainer/([^/]+)/?$', + ); + + foreach ($conflicting_patterns as $pattern) { + if (isset($rules[$pattern])) { + unset($rules[$pattern]); + } + } + + $wp_rewrite->rules = $rules; +}, 999); + +// Ensure pages load with their templates +add_filter('template_include', function($template) { + global $wp_query; + + if (is_404()) { + // Check if this should be a page + $path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'); + $page = get_page_by_path($path); + + if ($page && $page->post_status === 'publish') { + // Force WordPress to recognize this as a page + $wp_query->is_404 = false; + $wp_query->is_page = true; + $wp_query->is_singular = true; + $wp_query->queried_object = $page; + $wp_query->queried_object_id = $page->ID; + + // Set up post data + setup_postdata($page); + + // Get the correct template + $page_template = get_page_template_slug($page->ID); + if ($page_template) { + $located = locate_template(array($page_template)); + if ($located) { + return $located; + } + } + + // Fall back to page.php + return get_page_template(); + } + } + + return $template; +}, 5); +PHP + +# Flush everything +wp rewrite flush +wp cache flush + +echo "Routing fix applied!" +EOF \ No newline at end of file diff --git a/scripts/fix-template-recognition.sh b/scripts/fix-template-recognition.sh new file mode 100755 index 00000000..f8cb073f --- /dev/null +++ b/scripts/fix-template-recognition.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +echo "=== Fixing Template Recognition ===" + +# SSH into staging and fix template loading +ssh roodev@146.190.76.204 << 'EOF' +cd /home/974670.cloudwaysapps.com/uberrxmprk/public_html + +# First, let's check what WordPress thinks the template should be +echo "Checking page template assignment..." +PAGE_ID=5334 +TEMPLATE=$(wp post meta get $PAGE_ID _wp_page_template) +echo "Page $PAGE_ID has template: $TEMPLATE" + +# Clear the template and reassign it +echo "Clearing and reassigning template..." +wp post meta delete $PAGE_ID _wp_page_template +wp post meta add $PAGE_ID _wp_page_template "page-trainer-registration.php" + +# Also try setting it as default first, then back +wp post meta update $PAGE_ID _wp_page_template "default" +wp post meta update $PAGE_ID _wp_page_template "page-trainer-registration.php" + +# Let's also check if we need to use a different template path +echo -e "\nTrying alternate template assignment..." +wp post meta update $PAGE_ID _wp_page_template "astra-child-hvac/page-trainer-registration.php" + +# Check result +TEMPLATE_AFTER=$(wp post meta get $PAGE_ID _wp_page_template) +echo "Template after update: $TEMPLATE_AFTER" + +# Clear all caches +wp cache flush +wp breeze purge --cache=all +wp rewrite flush + +# Also update the child theme functions to better handle templates +echo -e "\nUpdating child theme template handling..." +cat > wp-content/themes/astra-child-hvac/functions-template-fix.php << 'PHP' + 'page-trainer-registration.php', + 'trainer/dashboard' => 'page-trainer-dashboard.php', + 'master-trainer/dashboard' => 'page-master-dashboard.php', + 'training-login' => 'page-trainer-login.php', + ); + + foreach ($template_map as $path => $template_file) { + if (strpos($page_path, $path) !== false) { + $child_template = get_stylesheet_directory() . '/' . $template_file; + if (file_exists($child_template)) { + return $child_template; + } + } + } + } + } + + return $template; +}, 99); +PHP + +# Include the fix in functions.php +echo -e "\n// Include template fix" >> wp-content/themes/astra-child-hvac/functions.php +echo "require_once('functions-template-fix.php');" >> wp-content/themes/astra-child-hvac/functions.php + +echo -e "\nTemplate fix applied!" +EOF \ No newline at end of file