Make WordPress Core

Opened 6 years ago

Last modified 5 years ago

#43274 new defect (bug)

Changing $(comments|feed)_base of WP_Rewrite causes errors because of hardcoded strings in redirect_canonical()

Reported by: dimadin's profile dimadin Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Canonical Keywords: has-patch needs-refresh needs-unit-tests
Focuses: Cc:


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 will not work. Feed URLs work in two places:|rss2?|rdf|atom) and|rss2?|rdf|atom) (see rules). When you open you match first rule where feed is type of feed. You need second rule to test it.

There is quick workaround though:

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.

Attachments (1)

43274.diff (2.9 KB) - added by dimadin 6 years ago.

Download all attachments as: .zip

Change History (6)

6 years ago

#1 @dimadin
6 years ago

  • Keywords has-patch added

#2 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 5.0

Related: #18084

#3 @peterwilsoncc
6 years ago

  • Keywords needs-refresh needs-unit-tests added


Are you able to wrap the variables in regular expressions with preg_quote() to ensure they're escaped correctly?

Some tests to ensure the function behaves as expected with custom bases would be great to see too.

#4 @johnbillion
6 years ago

  • Milestone changed from 5.0 to 5.1

#5 @pento
5 years ago

  • Milestone changed from 5.1 to Future Release

Patch needs refresh, and a whole lot of testing.

Note: See TracTickets for help on using tickets.