From 9224c3e2ce6e0ad3ad2f8ba184556c72c39a7593 Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Tue, 10 May 2022 16:39:29 +0100
Subject: [PATCH] Allow AJAX paths to work properly with a custom basepage (as
 can be used on WordPress frontend)

---
 civicrm/js/crm.ajax.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/civicrm/js/crm.ajax.js b/civicrm/js/crm.ajax.js
index 39f7c85ef9..1a4983cc3a 100644
--- a/civicrm/js/crm.ajax.js
+++ b/civicrm/js/crm.ajax.js
@@ -28,11 +28,13 @@
       path = path.split('#')[0];
     }
     frag = path.split('?');
+    // Remove basepage as it can be changed on some CMS eg. WordPress frontend.
+    frag[0] = frag[0].replace('civicrm/', '/');
     // Encode url path only if slashes in placeholder were also encoded
-    if (tplURL[mode].indexOf('civicrm/placeholder-url-path') >= 0) {
-      url = tplURL[mode].replace('civicrm/placeholder-url-path', frag[0]);
+    if (tplURL[mode].indexOf('/placeholder-url-path') >= 0) {
+      url = tplURL[mode].replace('/placeholder-url-path', frag[0]);
     } else {
-      url = tplURL[mode].replace('civicrm%2Fplaceholder-url-path', encodeURIComponent(frag[0]));
+      url = tplURL[mode].replace('%2Fplaceholder-url-path', encodeURIComponent(frag[0]));
     }
 
     if (_.isEmpty(query)) {
-- 
GitLab