WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#31300 new defect (bug)

redirect_canonical returns too early

Reported by: stephenharris Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Canonical Keywords: has-patch dev-feedback
Focuses: Cc:
PR Number:

Description

If $redirect_url is not set or is not equal to $requested_url then redirect_canonical() returns early and does not trigger the redirect_canonical filter. This prevents plugins from being able to alter the canonical URL.

This bug was partially addressed in #8975 (it still returned early when the redirect and requested URL are the same), but this was reverted in #11700 without any indication as to why.

The attached patch ensures the filter triggers even when the $redirect_url is not set or is the same as $requested_url.

Attachments (1)

31300.diff (994 bytes) - added by stephenharris 5 years ago.

Download all attachments as: .zip

Change History (4)

@stephenharris
5 years ago

#1 @stephenharris
5 years ago

  • Keywords has-patch dev-feedback added

Attached patch passes all canonical group unit tests, with one skipped (open trac ticket). My only concern which this patch is that redirect_canonical() seems to modify the $requested_url between where the early return was and the filter is. I'm confused as to why it modifies the requested URL not the redirect URL, but in my opinion this issue is independent of this ticket.

#2 @DrewAPicture
5 years ago

  • Version trunk deleted

#3 @mikejolley
4 years ago

I could also use this one - https://github.com/woothemes/woocommerce/issues/10619#issuecomment-203039875 - Core handles %category% canonical redirects, but if I want to do the same for a custom one, e.g. %product_category%, I cannot via this filter because it returns too early.

Note: See TracTickets for help on using tickets.