WordPress.org

Make WordPress Core

Changeset 4886


Ignore:
Timestamp:
02/15/2007 07:07:12 AM (11 years ago)
Author:
markjaquith
Message:

Consistent use or disuse of trailing slashes in URLs according to user preference. props MathiasBynens. fixes #1485

Location:
trunk/wp-includes
Files:
5 edited

Legend:

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

    r4795 r4886  
    3333
    3434        if ( $parent = $category->category_parent )
    35             $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename . '/';
     35            $category_nicename = get_category_parents($parent, false, '/', true) . $category_nicename;
    3636
    3737        $catlink = str_replace('%category%', $category_nicename, $catlink);
    38         $catlink = get_option('home') . trailingslashit($catlink);
     38        $catlink = get_option('home') . user_trailingslashit($catlink);
    3939    }
    4040    return apply_filters('category_link', $catlink, $category_id);
  • trunk/wp-includes/comment-template.php

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

    r4805 r4886  
    100100
    101101    if ( '' != get_option('permalink_structure') )
    102         $url = trailingslashit( get_permalink() ) . 'feed/';
     102        $url = trailingslashit( get_permalink() ) . user_trailingslashit('feed');
    103103    else
    104104        $url = get_option('home') . "/$commentsrssfilename?feed=rss2&p=$id";
     
    116116    } else {
    117117        $link = get_author_posts_url($author_id, $author_nicename);
    118         $link = $link . "feed/";
     118        $link = $link . user_trailingslashit('feed');
    119119    }
    120120
     
    134134    } else {
    135135        $link = get_category_link($cat_ID);
    136         $link = $link . "feed/";
     136        $link = $link . user_trailingslashit('feed/');
    137137    }
    138138
  • trunk/wp-includes/link-template.php

    r4721 r4886  
    99function permalink_link() { // For backwards compatibility
    1010    echo apply_filters('the_permalink', get_permalink());
     11}
     12
     13
     14/**
     15 * Conditionally adds a trailing slash if the permalink structure
     16 * has a trailing slash, strips the trailing slash if not
     17 * @global object Uses $wp_rewrite
     18 * @param $string string a URL with or without a trailing slash
     19 * @return string
     20 */
     21function user_trailingslashit($string) {
     22    global $wp_rewrite;
     23    if ( $wp_rewrite->use_trailing_slashes )
     24        $string = trailingslashit($string);
     25    else
     26        $string = preg_replace('|/$|', '', $string); // untrailing slash
     27    return $string;
    1128}
    1229
     
    117134        $link = get_page_uri($id);
    118135        $link = str_replace('%pagename%', $link, $pagestruct);
    119         $link = get_option('home') . "/$link/";
     136        $link = get_option('home') . "/$link";
     137        $link = user_trailingslashit($link);
    120138    } else {
    121139        $link = get_option('home') . "/?page_id=$id";
     
    159177    if ( !empty($yearlink) ) {
    160178        $yearlink = str_replace('%year%', $year, $yearlink);
    161         return apply_filters('year_link', get_option('home') . trailingslashit($yearlink), $year);
     179        return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink), $year);
    162180    } else {
    163181        return apply_filters('year_link', get_option('home') . '/?m=' . $year, $year);
     
    175193        $monthlink = str_replace('%year%', $year, $monthlink);
    176194        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
    177         return apply_filters('month_link', get_option('home') . trailingslashit($monthlink), $year, $month);
     195        return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink), $year, $month);
    178196    } else {
    179197        return apply_filters('month_link', get_option('home') . '/?m=' . $year . zeroise($month, 2), $year, $month);
     
    195213        $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
    196214        $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
    197         return apply_filters('day_link', get_option('home') . trailingslashit($daylink), $year, $month, $day);
     215        return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink), $year, $month, $day);
    198216    } else {
    199217        return apply_filters('day_link', get_option('home') . '/?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
     
    218236
    219237        $permalink = str_replace('%feed%', $feed, $permalink);
    220         $permalink = preg_replace('#/+#', '/', "/$permalink/");
    221         $output =  get_option('home') . $permalink;
     238        $permalink = preg_replace('#/+#', '/', "/$permalink");
     239        $output =  get_option('home') . user_trailingslashit($permalink);
    222240    } else {
    223241        if ( false !== strpos($feed, 'comments_') )
     
    436454    $qstr = preg_replace('|^/+|', '', $qstr);
    437455    if ( $permalink )
    438         $qstr = trailingslashit($qstr);
     456        $qstr = user_trailingslashit($qstr);
    439457    $qstr = preg_replace('/&([^#])(?![a-z]{1,8};)/', '&$1', trailingslashit( get_option('home') ) . $qstr );
    440458
    441459    // showing /page/1/ or ?paged=1 is redundant
    442460    if ( 1 === $pagenum ) {
    443         $qstr = str_replace('page/1/', '', $qstr); // for mod_rewrite style
     461        $qstr = str_replace(user_trailingslashit('index.php/page/1'), '', $qstr); // for PATHINFO style
     462        $qstr = str_replace(user_trailingslashit('page/1'), '', $qstr); // for mod_rewrite style
    444463        $qstr = remove_query_arg('paged', $qstr); // for query style
    445464    }
  • trunk/wp-includes/rewrite.php

    r4551 r4886  
    149149class WP_Rewrite {
    150150    var $permalink_structure;
     151    var $use_trailing_slashes;
    151152    var $category_base;
    152153    var $category_structure;
     
    877878        unset($this->feed_structure);
    878879        unset($this->comment_feed_structure);
     880        $this->use_trailing_slashes = ( substr($this->permalink_structure, -1, 1) == '/' ) ? true : false;
    879881    }
    880882
Note: See TracChangeset for help on using the changeset viewer.