WordPress.org

Make WordPress Core

Changeset 5019


Ignore:
Timestamp:
03/10/2007 06:18:43 AM (11 years ago)
Author:
markjaquith
Message:

user_trailingslashit filter for users who sometimes want trailing slashes only on certain URL types. fixes #3899

Location:
trunk/wp-includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r4953 r5019  
    3636
    3737        $catlink = str_replace('%category%', $category_nicename, $catlink);
    38         $catlink = get_option('home') . user_trailingslashit($catlink);
     38        $catlink = get_option('home') . user_trailingslashit($catlink, 'category');
    3939    }
    4040    return apply_filters('category_link', $catlink, $category_id);
  • trunk/wp-includes/comment-template.php

    r4990 r5019  
    227227
    228228    if ( '' != get_option('permalink_structure') )
    229         $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback');
     229        $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
    230230
    231231    return $tb_url;
  • trunk/wp-includes/feed.php

    r4990 r5019  
    114114    } else {
    115115        $link = get_author_posts_url($author_id, $author_nicename);
    116         $link = $link . user_trailingslashit('feed');
     116        $link = $link . user_trailingslashit('feed', 'feed');
    117117    }
    118118
     
    132132    } else {
    133133        $link = get_category_link($cat_ID);
    134         $link = $link . user_trailingslashit('feed/');
     134        $link = $link . user_trailingslashit('feed', 'feed');
    135135    }
    136136
  • trunk/wp-includes/link-template.php

    r4990 r5019  
    1717 * @global object Uses $wp_rewrite
    1818 * @param $string string a URL with or without a trailing slash
     19 * @param $type_of_url string the type of URL being considered (e.g. single, category, etc) for use in the filter
    1920 * @return string
    2021 */
    21 function user_trailingslashit($string) {
     22function user_trailingslashit($string, $type_of_url = '') {
    2223    global $wp_rewrite;
    2324    if ( $wp_rewrite->use_trailing_slashes )
    2425        $string = trailingslashit($string);
    2526    else
    26         $string = preg_replace('|/$|', '', $string); // untrailing slash
     27        $string = preg_replace('|/+$|', '', $string); // untrailing slash
     28
     29    // Note that $type_of_url can be one of following:
     30    // single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged
     31    $string = apply_filters('user_trailingslashit', $string, $type_of_url);
    2732    return $string;
    2833}
     
    95100            $post->post_name,
    96101        );
    97         return apply_filters('post_link', get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post);
     102        $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
     103        $permalink = user_trailingslashit($permalink, 'single');
     104        return apply_filters('post_link', $permalink, $post);
    98105    } else { // if they're not using the fancy permalink option
    99106        $permalink = get_option('home') . '/?p=' . $post->ID;
     
    135142        $link = str_replace('%pagename%', $link, $pagestruct);
    136143        $link = get_option('home') . "/$link";
    137         $link = user_trailingslashit($link);
     144        $link = user_trailingslashit($link, 'page');
    138145    } else {
    139146        $link = get_option('home') . "/?page_id=$id";
     
    177184    if ( !empty($yearlink) ) {
    178185        $yearlink = str_replace('%year%', $year, $yearlink);
    179         return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink), $year);
     186        return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
    180187    } else {
    181188        return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year);
     
    193200        $monthlink = str_replace('%year%', $year, $monthlink);
    194201        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
    195         return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink), $year, $month);
     202        return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
    196203    } else {
    197204        return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
     
    213220        $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
    214221        $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
    215         return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink), $year, $month, $day);
     222        return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
    216223    } else {
    217224        return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
     
    237244        $permalink = str_replace('%feed%', $feed, $permalink);
    238245        $permalink = preg_replace('#/+#', '/', "/$permalink");
    239         $output =  get_option('home') . user_trailingslashit($permalink);
     246        $output =  get_option('home') . user_trailingslashit($permalink, 'feed');
    240247    } else {
    241248        if ( false !== strpos($feed, 'comments_') )
     
    258265        if ( 'rss2' != $feed )
    259266            $url .= "/$feed";
    260         $url = user_trailingslashit($url);
     267        $url = user_trailingslashit($url, 'single_feed');
    261268    } else {
    262269        $url = get_option('home') . "/?feed=$feed&p=$id";
     
    472479    $qstr = preg_replace('|^/+|', '', $qstr);
    473480    if ( $permalink )
    474         $qstr = user_trailingslashit($qstr);
     481        $qstr = user_trailingslashit($qstr, 'paged');
    475482    $qstr = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', trailingslashit( get_option('home') ) . $qstr );
    476483
    477484    // showing /page/1/ or ?paged=1 is redundant
    478485    if ( 1 === $pagenum ) {
    479         $qstr = str_replace(user_trailingslashit('index.php/page/1'), '', $qstr); // for PATHINFO style
    480         $qstr = str_replace(user_trailingslashit('page/1'), '', $qstr); // for mod_rewrite style
     486        $qstr = str_replace(user_trailingslashit('index.php/page/1', 'paged'), '', $qstr); // for PATHINFO style
     487        $qstr = str_replace(user_trailingslashit('page/1', 'paged'), '', $qstr); // for mod_rewrite style
    481488        $qstr = remove_query_arg('paged', $qstr); // for query style
    482489    }
  • trunk/wp-includes/post-template.php

    r5018 r5019  
    162162                            $output .= '<a href="' . get_permalink() . '&amp;page=' . $i . '">';
    163163                        else
    164                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i) . '">';
     164                            $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
    165165                    }
    166166                }
     
    181181                            $output .= '<a href="' . get_permalink() . '&amp;page=' . $i . '">' . $previouspagelink . '</a>';
    182182                        else
    183                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i) . '">' . $previouspagelink . '</a>';
     183                            $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $previouspagelink . '</a>';
    184184                    }
    185185                }
     
    192192                            $output .= '<a href="' . get_permalink() . '&amp;page=' . $i . '">' . $nextpagelink . '</a>';
    193193                        else
    194                             $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i) . '">' . $nextpagelink . '</a>';
     194                            $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $nextpagelink . '</a>';
    195195                    }
    196196                }
Note: See TracChangeset for help on using the changeset viewer.