Frontend Clean URLs is sometimes generating backend URLs on pages with shortcodes
While setting up CiviEvent Calendar for a client I came across an odd situation where the event links were produced as backend links via a shortcode
How to Reproduce
- Setup some Events
- Install CiviEvent Calendar
- Copy over the WP plugin and activate
- Add a shortcode to a Page like
Test
- See the Events appear as
https://mysite.org/?civiwp=CiviCRM&q=civicrm%2Fevent%2Finfo&id=27
What was expected
I thought that the URL would appear as a normal civicrm/event/info&id=27
link.
Other Details
I found one issue in their own extension that was no properly passing the url
function properly so I fixed that. Even doing so it seems to not function properly. It is now
$url = CRM_Utils_System::url('civicrm/event/info', // path
'id=' . $dao->id ?? NULL, // query
TRUE, // absolute
NULL, // fragement
FALSE, // htmlize
TRUE, // Frontend
FALSE // Backend
);
They are doing the following code to generate the shortcode from their own code (note: I added the new url/base
hook but that still didn't work
// Call wp_frontend with $shortcode param.
add_filter('civicrm/core/url/base', 'event_calendar_fixed_base_url');
if (class_exists('CiviCRM_For_WordPress')) {
civi_wp()->invoke();
$content = ob_get_clean(); // save the output and flush the buffer
return $content;
}
else {
return civicrm_wp_frontend(TRUE);
}
remove_filter('civicrm/core/url/base', 'event_calendar_fixed_base_url');
}
}
function event_calendar_fixed_base_url() {
return CRM_Utils_System::getBaseUrl(TRUE, TRUE, FALSE);
}
I narrowed the code down to this line. The $frontend_line
gets set, but it's not the basepage. Then it's basically used farther down (I think) instead of the basePage even thought we asked for a FrontEnd link. I actually think that instead of the else here we should just remove it and do the check anyway, but this is complex logic so maybe I don't understand.
I wanted to report it to discuss a bit because A) maybe there is something wrong in the rendering for CiviEvents that is a quick fix or B) this is a bigger problem