[wp-trac] [WordPress Trac] #43274: Changing $(comments|feed)_base of WP_Rewrite causes errors because of hardcoded strings in redirect_canonical()

WordPress Trac noreply at wordpress.org
Fri Feb 9 21:11:39 UTC 2018


#43274: Changing $(comments|feed)_base of WP_Rewrite causes errors because of
hardcoded strings in redirect_canonical()
--------------------------+-----------------------------
 Reporter:  dimadin       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Canonical     |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When you change `$comments_base`/`$feed_base` for `WP_Rewrite` instance,
 URLs with that base will not work because `comments` and `feed` strings
 are hardcoded in a few places in `redirect_canonical()`. Changing these to
 use `$wp_rewrite->comments_base` and `$wp_rewrite->feed_base` respectively
 will fix this issue.

 NOTE: When testing feed URLs, changing `feed` with `feed_base` in
 `example.com/feed/` will not work. Feed URLs work in two places:
 `example.com/(feed|rss2?|rdf|atom)` and
 `example.com/feed_base/(feed|rss2?|rdf|atom)`
 ([https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-
 rewrite.php?rev=42343#L860 see rules]). When you open `example.com/feed/`
 you match first rule where `feed` is type of feed. You need second rule to
 test it.

 There is quick workaround though:

 {{{#!php
 add_action( 'after_setup_theme', function() {
         $GLOBALS['wp_rewrite']->feed_base = 'mycustomfeedbase';
         $GLOBALS['wp_rewrite']->feeds[] = 'mycustomfeedbase';
 } );

 add_action( 'parse_query', function( $q ) {
         if ( $GLOBALS['wp_rewrite']->feed_base == $q->get( 'feed' ) ) {
                 $q->set( 'feed', 'feed' );
         }
 } );
 }}}

 Don't forget to flush rewrite rules.

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


More information about the wp-trac mailing list