Skip to content

Instantly share code, notes, and snippets.

@kcristiano
Created October 30, 2018 21:21
Show Gist options
  • Save kcristiano/7cf54ad24105c1cdef14d2b2f5642b86 to your computer and use it in GitHub Desktop.
Save kcristiano/7cf54ad24105c1cdef14d2b2f5642b86 to your computer and use it in GitHub Desktop.
diff --git a/CRM/Utils/System/WordPress.php b/CRM/Utils/System/WordPress.php
index f2df6c8476..493e174f79 100644
--- a/CRM/Utils/System/WordPress.php
+++ b/CRM/Utils/System/WordPress.php
@@ -208,6 +208,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
$fragment = isset($fragment) ? ('#' . $fragment) : '';
$path = CRM_Utils_String::stripPathChars($path);
+ $basepage = FALSE;
//this means wp function we are trying to use is not available,
//so load bootStrap
@@ -215,16 +216,20 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
if (!function_exists('get_option')) {
$this->loadBootStrap();
}
+
if ($config->userFrameworkFrontend) {
+ global $post;
if (get_option('permalink_structure') != '') {
- global $post;
$script = get_permalink($post->ID);
}
-
+ if ($config->wpBasePage == $post->post_name) {
+ $basepage = TRUE;
+ }
// when shortcode is included in page
// also make sure we have valid query object
+ // FIXME: $wpPageParam has no effect and is only set on the *basepage*
global $wp_query;
- if (method_exists($wp_query, 'get')) {
+ if (get_option('permalink_structure') == '' && method_exists($wp_query, 'get')) {
if (get_query_var('page_id')) {
$wpPageParam = "page_id=" . get_query_var('page_id');
}
@@ -251,18 +256,61 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
}
$queryParts = array();
- if (isset($path)) {
- $queryParts[] = 'page=CiviCRM';
- $queryParts[] = "q={$path}";
+
+ // CRM_Core_Payment::getReturnSuccessUrl() passes $query as an array
+ if (isset($query) && is_array($query)) {
+ $query = implode($separator, $query);
}
- if ($wpPageParam) {
- $queryParts[] = $wpPageParam;
+
+ if (
+ // not using clean URLs
+ !$config->cleanURL
+ // requesting an admin URL
+ || ((is_admin() && !$frontend) || $forceBackend)
+ // is shortcode
+ || (!$basepage && $script != '')
+ ) {
+
+ // pre-existing logic
+ if (isset($path)) {
+ $queryParts[] = 'page=CiviCRM';
+ // Encode all but the *path* placeholder
+ if ($path !== '*path*') {
+ $path = rawurlencode($path);
+ }
+ $queryParts[] = "q={$path}";
+ }
+ if ($wpPageParam) {
+ $queryParts[] = $wpPageParam;
+ }
+ if (isset($query)) {
+ $queryParts[] = $query;
+ }
+
+ $final = $base . '?' . implode($separator, $queryParts) . $fragment;
+
}
- if (isset($query)) {
- $queryParts[] = $query;
+ else {
+
+ // clean URLs
+ if (isset($path)) {
+ $base = trailingslashit($base) . str_replace('civicrm/', '', $path) . '/';
+ }
+ if (isset($query)) {
+ $query = ltrim($query, '=?&');
+ $queryParts[] = $query;
+ }
+
+ if (!empty($queryParts)) {
+ $final = $base . '?' . implode($separator, $queryParts) . $fragment;
+ }
+ else {
+ $final = $base . $fragment;
+ }
+
}
- return $base . '?' . implode($separator, $queryParts) . $fragment;
+ return $final;
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment