[wp-trac] [WordPress Trac] #50084: redirect_canonical() need additional hook

WordPress Trac noreply at wordpress.org
Mon May 4 18:52:25 UTC 2020


#50084: redirect_canonical() need additional hook
--------------------------+-----------------------------
 Reporter:  Tkama         |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 There is no hook in [redirect_canonical()](https://wp-kama.ru/filecode/wp-
 includes/canonical.php#L12-625) function that allow as to extend it's
 logic.

 For example, I have the following permastructure `/%post_id%/%post_name%`.
 And I can visit the post by such URL `/123`. But I need the redirect to
 right URL `/123/postname`.

 And if I try to use the `redirect_canonical` hook to fix this BUG, the
 hook won't work, because it's too late and the hook is never triggers.

 At the bottom of the function [we have such code](https://wp-
 kama.ru/filecode/wp-includes/canonical.php#L572-605):

 {{{#!php
 <?php
         if ( ! $redirect_url || $redirect_url == $requested_url ) {
                 return;
         }

 ...
         $redirect_url = apply_filters( 'redirect_canonical',
 $redirect_url, $requested_url );

 }}}

 Why there is no hook before `return`? Hook that allows us set our own
 `$redirect_url`...

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50084>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list