Opened 2 years ago
Last modified 2 years ago
#16557 new enhancement
Ability to disable redirect_guess_404_permalink()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Canonical | Version: | 3.1 |
| Severity: | minor | Keywords: | has-patch dev-feedback |
| Cc: | msafi, simon@… |
Description
Can you make redirect_guess_404_permalink() pluggable or have its return value pass-through a filter so that developers can override it?
I know I can remove_filter('template_redirect', 'redirect_canonical') but redirect_canonical is too useful to be disabled. Only disabling URL guessing would be great.
Thanks a lot,
MK
Attachments (2)
Change History (10)
- Keywords needs-patch added; URL guessing URL redirect removed
- Milestone changed from Awaiting Review to Future Release
simonwheatley — 2 years ago
One possibility to allow filtering the where clauses for posts and pages
comment:4
simonwheatley — 2 years ago
- Cc simon@… added
- Keywords has-patch dev-feedback added; needs-patch removed
- Version changed from 3.0.5 to 3.1
Added a possible patch which separates the where clauses into page related and post related, and allows plugin devs to filter either snippet of SQL.
Patch created against 3.1.1.
What I'd like to do is simply make redirect_guess_404_permalink() actually hook into redirect_canonical(), I guess as a filter since it returns data. Then the filter can be removed.
So instead of:
if ( ! $redirect_url ) $redirect_url = redirect_guess_404_permalink();
Instead do:
$redirect_url = apply_filters( 'redirect_guess_404_permalink', $redirect_url );
And hook the function into there. Then it may be removed. Also, the filter name is lame -- perhaps can be more generic considering the positioning.
comment:6
simonwheatley — 2 years ago
@nacin - Thanks for the steer. Is the attached diff what you were looking for?
Replying to nacin:
What I'd like to do is simply make redirect_guess_404_permalink() actually hook into redirect_canonical(), I guess as a filter since it returns data. Then the filter can be removed.
So instead of:
if ( ! $redirect_url ) $redirect_url = redirect_guess_404_permalink();
Can we not just hook redirect_guess_404_permalink() onto redirect_canonical and be done with it - no new filters needed?
Instead do:
$redirect_url = apply_filters( 'redirect_guess_404_permalink', $redirect_url );And hook the function into there. Then it may be removed. Also, the filter name is lame -- perhaps can be more generic considering the positioning.
comment:8
in reply to:
↑ 7
simonwheatley — 2 years ago
Replying to westi:
Can we not just hook redirect_guess_404_permalink() onto redirect_canonical and be done with it - no new filters needed?
That would involve moving the point that the redirect guessing is done, which (from limited testing just now) means the current guessing behaviour doesn't happen. I favour the additional filter as per my most recent patch.

+1. In fact I thought I already created this ticket. It should probably be attached into redirect_canonical() through a filter.
Whipped this up not long ago, as a workaround:
function remove_redirect_guess_404_permalink( $redirect_url ) { if ( is_404() ) return false; return $redirect_url; } add_filter( 'redirect_canonical', 'remove_redirect_guess_404_permalink' );