Make WordPress Core


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

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

File:
1 edited

Legend:

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