Attempting to create a pretty URL on a subpage results in non-pretty URL
I discovered a strange issue today with regards to pretty CiviCRM Urls via the implemention CRM_Utils_System::url
for Wordpress
To recreate
- Create a subpage called
Profile
- In
functions.php
create a function like
civicrm_initialize();
$url = '';
$result = get_user_participation($current_user, $event_id);
if (!empty($result) && isset($result['values'][0]['participant_id'])) {
$pid = $result['values'][0]['participant_id'];
$eligible = CRM_Event_BAO_Participant::getSelfServiceEligibility($pid, '', FALSE)['eligible'];
if ($eligible) {
$checksum = \Civi\Api4\Contact::getChecksum(FALSE)->setContactId($result['values'][0]['contact_id'])->execute()->first()['checksum'];
$url = CRM_Utils_System::url("/civicrm/event/selfsvcupdate", "reset=1&pid=$pid&cs=$checksum", TRUE, FALSE, TRUE);
}
}
return $url;
}
3. Override the ```Profile``` page within your theme by creating ```Profile.php``` (Note: I didn't test if we use a shortcode here)
- Call the function above to output the URL
Result
The logic in the code determines if we have a basepage, and if it doesn't find one well it resorts to creating a non-pretty path.
I don't think that I'm proposing we change this, but it could be good to be able to override this maybe in the function call? To force it to make pretty links regardless, because on some subpages for sure we would want to have nice links.
Ironically, the link generated doesn't work in this case either. When it's a pretty link it's fine but otherwise no dice. It could be a configuration issue with my client I'm not sure.