WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 5 weeks ago

#16557 new enhancement

Ability to disable redirect_guess_404_permalink()

Reported by: msafi Owned by:
Milestone: Future Release Priority: normal
Severity: minor Version: 3.1
Component: Canonical Keywords: has-patch dev-feedback 4.0-early
Focuses: Cc:

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 3 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 3 years ago.
New filter to replace redirect_guess_404_permalink

Download all attachments as: .zip

Change History (15)

comment:1 msafi3 years ago

  • Cc msafi added

comment:2 nacin3 years ago

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

comment:3 msafi3 years ago

Oh, this is a good idea, thanks!

simonwheatley3 years ago

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

comment:4 simonwheatley3 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.

comment:5 nacin3 years ago

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.

simonwheatley3 years ago

New filter to replace redirect_guess_404_permalink

comment:6 simonwheatley3 years ago

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

comment:7 follow-up: westi3 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();

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.

Can we not just hook redirect_guess_404_permalink() onto redirect_canonical and be done with it - no new filters needed?

Last edited 3 years ago by westi (previous) (diff)

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

comment:9 mboynes9 months ago

  • Cc mboynes@… added

I'd love to see this finally make its way into core. Is there anything in particular holding it up?

comment:10 joostdevalk6 months ago

I see no reason why the first, very simple, patch could not just be committed and make everybody happy....

comment:11 Lex_Robinson3 months ago

Could this be merged please? I need it.

comment:12 MikeSchinkel5 weeks ago

In preparing for my WordCamp Atlanta talk about URL routing I've run into this function causing all kind of headache for customized URLs.

There's a reason for the HTTP 404 status code, incorrect URLs are incorrect and the client searching for them should be told so! :)

The problem with this is it can return one resource today and another resource in the future after the user added a higher priority "guess."

My vote is (for my own sites at least) to fully disable this functionality Please address this so we can use plugins to fully control our URLs.

Thanks!

P.S. Related #19693

comment:13 SergeyBiryukov5 weeks ago

  • Keywords 4.0-early added
Note: See TracTickets for help on using tickets.