Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21788 Clean URLs in WordPress #11708

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CRM/Core/QuickForm/Action/Jump.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public function perform(&$page, $actionName) {
}
// generate the URL for the page 'display' event and redirect to it
$action = $current->getAttribute('action');
// prevent URLs that end in ? from causing redirects
$action = rtrim($action, '?');
// FIXME: this should be passed through CRM_Utils_System::url()
$url = $action . (FALSE === strpos($action, '?') ? '?' : '&') . $current->getButtonName('display') . '=true' . '&qfKey=' . $page->get('qfKey');

CRM_Utils_System::redirect($url);
Expand Down
61 changes: 51 additions & 10 deletions CRM/Utils/System/WordPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,21 +208,26 @@ public function url(
$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
// FIXME: Why bootstrap in url()? Generally want to define 1-2 strategic places to put bootstrap
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_query_var('page_id')) {
Expand Down Expand Up @@ -251,18 +256,54 @@ public function url(
}

$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 (
!$config->cleanURL // not using clean URLs
|| ((is_admin() && !$frontend) || $forceBackend) // requesting an admin URL
|| (!$basepage && $script != '') // is shortcode
) {

// pre-existing logic
if (isset($path)) {
$queryParts[] = 'page=CiviCRM';
$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;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions templates/CRM/common/civicrm.settings.php.template
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ if (!defined('CIVICRM_CLEANURL')) {
elseif ( function_exists('config_get') && config_get('system.core', 'clean_url') != 0) {
define('CIVICRM_CLEANURL', 1 );
}
elseif( function_exists('get_option') && get_option('permalink_structure') != '' ) {
define('CIVICRM_CLEANURL', 1);
}
else {
define('CIVICRM_CLEANURL', 0);
}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/common/paymentBlock.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@

var payment_instrument_id = $('#payment_instrument_id').val();

var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="&formName=`$form.formName`&currency=`$currency`&`$urlPathVar``$isBackOfficePathVar``$profilePathVar``$contributionPageID``$preProfileID`processor_id="}" + type;
var dataUrl = "{crmURL p='civicrm/payment/form' h=0 q="formName=`$form.formName`&currency=`$currency`&`$urlPathVar``$isBackOfficePathVar``$profilePathVar``$contributionPageID``$preProfileID`processor_id="}" + type;
{literal}
if (typeof(CRM.vars) != "undefined") {
if (typeof(CRM.vars.coreForm) != "undefined") {
Expand Down