Opened 2 years ago

Last modified 2 years ago

#16557 new enhancement

Ability to disable redirect_guess_404_permalink()

Reported by: msafi 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)

filters to tweak permalink guessing.diff (1.8 KB) - added by simonwheatley 2 years ago.
One possibility to allow filtering the where clauses for posts and pages
new filter to replace redirect_guess_404_permalink.diff (705 bytes) - added by simonwheatley 2 years ago.
New filter to replace redirect_guess_404_permalink

Download all attachments as: .zip

Change History (10)

  • Cc msafi added
  • Keywords needs-patch added; URL guessing URL redirect removed
  • Milestone changed from Awaiting Review to Future Release

+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' );

Oh, this is a good idea, thanks!

One possibility to allow filtering the where clauses for posts and pages

  • 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.

New filter to replace redirect_guess_404_permalink

@nacin - Thanks for the steer. Is the attached diff what you were looking for?

comment:7 follow-up: ↓ 8   westi2 years ago

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.

Version 0, edited 2 years ago by westi (next)

comment:8 in reply to: ↑ 7   simonwheatley2 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.

Note: See TracTickets for help on using tickets.