wp-rest - Adjust extern URL. Be more defensive about 'query' part. #192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
hook_civicrm_alterExternUrl
allows for modifications to certain callback URLs (e.g. CiviMail open/click-through URLs). As a hook, there may be multiple parties which weigh-in.This fixes an interaction that arises in the following conditions:
CIVICRM_WP_REST_REPLACE_MAILING_TRACKING
toTRUE
Before
The tracked link is converted to something like
On the plus side, this includes query parameters
u=5&qid=67
- which are important inputs for anyextern/url
-style end-point.On the downside, the URL is mixing up artifacts which identify different end-points, ie
wp-json/civicrm/v3/url
suggests thewp-rest
end-point?page=CiviCRM&q=civicrm/mailing/url
suggests the #17312 end-pointAfter
The tracked link appears as:
Notice that this unambiguously uses the
wp-rest
end-point. It includes the importantu=5&qid=67
.Technical Details
The contract for
hook_civicrm_alterExternUrl
allows multiple parties to weigh-in on the URL. In this case, we have 3 parties which can generate the URL:wp-rest
routesThis is prioritized such that
wp-rest
will override the URLs suggested by #17312.Aside: When using
alterExternUrl
to change the end-point, it seems perhaps most robust to build$url
from scratch -- ie don't read anything from$url
, read it from the request-values in$path
and$query
. I've suggested some updates to the examples: civicrm/civicrm-dev-docs#807