From 3cd485d7ab8da1c40f0c03d1f8b2315236b7817d Mon Sep 17 00:00:00 2001 From: Shane Date: Thu, 8 May 2025 22:04:57 -0400 Subject: [PATCH] dev/wordpress#153 Fixing regex issue whereby the rewrite defaults to the primary language --- includes/compatibility/civicrm.wpml.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/includes/compatibility/civicrm.wpml.php b/includes/compatibility/civicrm.wpml.php index e3a7f0e..796fe8a 100644 --- a/includes/compatibility/civicrm.wpml.php +++ b/includes/compatibility/civicrm.wpml.php @@ -155,12 +155,14 @@ public function rewrite_rules($flush_rewrite_rules, $basepage) { $converted_url = $sitepress->convert_url($url, $slug); $parsed_url = wp_parse_url($converted_url, PHP_URL_PATH); $regex_path_converted = substr($parsed_url, 1); - - $collected_rewrites[$basepage->ID][] = $regex_path; - $collected_rewrites[$basepage->ID][] = $regex_path_converted; - $collected_rewrites[$post_id][] = $regex_path; - $collected_rewrites[$post_id][] = $regex_path_converted; - + if ($basepage->ID == $post_id) { + $collected_rewrites[$basepage->ID][] = $regex_path; + $collected_rewrites[$basepage->ID][] = $regex_path_converted; + } + else { + // Add only the language specific regex path + $collected_rewrites[$post_id][] = $regex_path_converted; + } } // Make collection unique and add remaining rewrite rules.