Make WordPress Core

Opened 7 years ago

Last modified 3 years ago

#40176 new defect (bug)

Filter user_trailingslashit called with inconsistent $type_of_string for Post-Tags

Reported by: andi-dittrich's profile Andi Dittrich Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7.3
Component: Permalinks Keywords: 2nd-opinion dev-feedback
Focuses: Cc:


It seems to be a general inconsistency issue with the handling of post-tags in combination with the user_trailingslashit function/filter.

Assumption: $type_of_string should be consitent and of type tag or post_tag


Permalink Structure with Trailing-Slash:


Testcode to produce debug output

// disable canoncial redirects
add_action('redirect_canonical', '__return_false');

// show all events with tag/ urls
add_filter('user_trailingslashit', function($string, $type_of_url){
  if (strpos($string, 'tag/') !== false){

     echo 'Tag Link: ', $string, ' of type ', $type_of_url, PHP_EOL;
}, 100, 2);

Expected behaviour

Outputs like Tag Link: /tag/mytag1/ of type post_tag everytimes the url is of type Tag

Current behaviour

On Post Pages: Tag Link: /tag/mytag1/ of type category for related post-tag links
On Canoncial Redirects: Tag Link: /tag/mytag1/ of type category AND Tag Link: /tag/mytag1/ of type (not set!)

Identified Issues

wp-includes/canoncial.php line 425

its not checked if current page if of type tag

foreach ( array('single', 'category', 'page', 'day', 'month', 'year', 'home') as $type ) {

wp-includes/taxonomy.php line 3882

the $type_of_string variable is set to category by default instead of $taxonomy

$termlink = home_url( user_trailingslashit($termlink, 'category') );

Change History (1)

#1 @Andi Dittrich
7 years ago

  • Keywords 2nd-opinion dev-feedback added
Note: See TracTickets for help on using tickets.