Opened 7 years ago
Last modified 6 years ago
#43274 new defect (bug)
Changing $(comments|feed)_base of WP_Rewrite causes errors because of hardcoded strings in redirect_canonical()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Canonical | Keywords: | has-patch needs-refresh needs-unit-tests |
Focuses: | Cc: |
Description
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)
(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:
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.
Related: #18084