Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.