[wp-trac] [WordPress Trac] #16557: Ability to disable redirect_guess_404_permalink()
    WordPress Trac 
    noreply at wordpress.org
       
    Sun Dec 29 23:30:01 UTC 2019
    
    
  
#16557: Ability to disable redirect_guess_404_permalink()
------------------------------------+-----------------------------
 Reporter:  msafi                   |       Owner:  (none)
     Type:  defect (bug)            |      Status:  new
 Priority:  normal                  |   Milestone:  Future Release
Component:  Canonical               |     Version:  3.1
 Severity:  normal                  |  Resolution:
 Keywords:  has-patch dev-feedback  |     Focuses:
------------------------------------+-----------------------------
Comment (by apedog):
 I've written a clean fresh patch that I believe addresses all the issues
 raised in this ticket.
 I've added 3 new filters to {{{redirect_guess_404_permalink()}}}:
 - {{{'do_redirect_guess_404_permalink'}}} - Allows disabling 404 guessing
 altogether.
 {{{
 add_filter('do_redirect_guess_404_permalink', '__return_false');
 }}}
 - {{{'pre_redirect_guess_404_permalink'}}} - Allows short-circuit of
 function and returning a custom guess from a callback. This is a much
 needed functionality IMO. Especially with current WordPress handling. A
 very easy way for plugins to hook in a custom guessing function while not
 breaking anything else.
 {{{
 add_filter('pre_redirect_guess_404_permalink', 'my_custom_guess');
 function my_custom_guess($pre){
     return home_url('did-i-guess-right');
 }
 }}}
 - {{{'strict_redirect_guess_404_permalink'}}} - Allows strict guesses
 using {{{post_name = %s}}} SQL query instead of expensive (and overly
 broad) {{{post_name LIKE %s}}}} query. So {{{slug}}} might redirect to
 {{{parent/slug}}} but not to {{{sluggish-day}}}. Default is the current
 non-strict {{{LIKE}}} query.
 {{{
 add_filter('strict_redirect_guess_404_permalink', '__return_true');
 }}}
 All filters are nested within single function. So code and logic are all
 neatly tucked in one place. Nice for cohesion.
 I've tested these filters locally and they work.
 ----
 - Filters {{{'do_redirect_guess_404_permalink'}}} and
 {{{'pre_redirect_guess_404_permalink'}}} can be merged into a single
 filter. But semantically, disabling and short-circuiting are separate
 concerns so I figured two filters would be clearer.
 - Filter {{{'strict_redirect_guess_404_permalink'}}} touches the actual
 logic. And might merit discussion. So maybe it could be considered
 separately from the short-circuit filters.
 @markjaquith
-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/16557#comment:41>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
    
    
More information about the wp-trac
mailing list