Make WordPress Core


Ignore:
Timestamp:
01/04/2010 05:23:29 PM (15 years ago)
Author:
ryan
Message:

Introduce home_url(). Props Denis-de-Bernardy, hakre. see #9008

File:
1 edited

Legend:

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

    r12597 r12598  
    151151            $post->post_name,
    152152        );
    153         $permalink = get_option('home') . str_replace($rewritecode, $rewritereplace, $permalink);
     153        $permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) );
    154154        $permalink = user_trailingslashit($permalink, 'single');
    155155        return apply_filters('post_link', $permalink, $post, $leavename);
    156156    } else { // if they're not using the fancy permalink option
    157         $permalink = trailingslashit(get_option('home')) . '?p=' . $post->ID;
     157        $permalink = home_url('?p=' . $post->ID);
    158158        return apply_filters('post_link', $permalink, $post, $leavename);
    159159    }
     
    196196
    197197    if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
    198         $link = get_option('home');
     198        $link = home_url();
    199199    else
    200200        $link = _get_page_link( $id , $leavename, $sample );
     
    229229        $link = get_page_uri($id);
    230230        $link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
    231         $link = trailingslashit(get_option('home')) . $link;
     231        $link = home_url($link);
    232232        $link = user_trailingslashit($link, 'page');
    233233    } else {
    234         $link = trailingslashit(get_option('home')) . "?page_id=$id";
     234        $link = home_url("?page_id=$id");
    235235    }
    236236
     
    294294    if ( !empty($yearlink) ) {
    295295        $yearlink = str_replace('%year%', $year, $yearlink);
    296         return apply_filters('year_link', get_option('home') . user_trailingslashit($yearlink, 'year'), $year);
     296        return apply_filters('year_link', home_url( user_trailingslashit($yearlink, 'year') ), $year);
    297297    } else {
    298         return apply_filters('year_link', trailingslashit(get_option('home')) . '?m=' . $year, $year);
     298        return apply_filters('year_link', home_url('?m=' . $year), $year);
    299299    }
    300300}
     
    319319        $monthlink = str_replace('%year%', $year, $monthlink);
    320320        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
    321         return apply_filters('month_link', get_option('home') . user_trailingslashit($monthlink, 'month'), $year, $month);
     321        return apply_filters('month_link', home_url( user_trailingslashit($monthlink, 'month') ), $year, $month);
    322322    } else {
    323         return apply_filters('month_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2), $year, $month);
     323        return apply_filters('month_link', home_url( '?m=' . $year . zeroise($month, 2) ), $year, $month);
    324324    }
    325325}
     
    349349        $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
    350350        $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
    351         return apply_filters('day_link', get_option('home') . user_trailingslashit($daylink, 'day'), $year, $month, $day);
     351        return apply_filters('day_link', home_url( user_trailingslashit($daylink, 'day') ), $year, $month, $day);
    352352    } else {
    353         return apply_filters('day_link', trailingslashit(get_option('home')) . '?m=' . $year . zeroise($month, 2) . zeroise($day, 2), $year, $month, $day);
     353        return apply_filters('day_link', home_url( '?m=' . $year . zeroise($month, 2) . zeroise($day, 2) ), $year, $month, $day);
    354354    }
    355355}
     
    378378        $permalink = str_replace('%feed%', $feed, $permalink);
    379379        $permalink = preg_replace('#/+#', '/', "/$permalink");
    380         $output =  get_option('home') . user_trailingslashit($permalink, 'feed');
     380        $output =  home_url( user_trailingslashit($permalink, 'feed') );
    381381    } else {
    382382        if ( empty($feed) )
     
    386386            $feed = str_replace('comments_', 'comments-', $feed);
    387387
    388         $output = trailingslashit(get_option('home')) . "?feed={$feed}";
     388        $output = home_url("?feed={$feed}");
    389389    }
    390390
     
    418418        $type = get_post_field('post_type', $post_id);
    419419        if ( 'page' == $type )
    420             $url = trailingslashit(get_option('home')) . "?feed=$feed&page_id=$post_id";
     420            $url = home_url("?feed=$feed&page_id=$post_id");
    421421        else
    422             $url = trailingslashit(get_option('home')) . "?feed=$feed&p=$post_id";
     422            $url = home_url("?feed=$feed&p=$post_id");
    423423    }
    424424
     
    472472
    473473    if ( '' == $permalink_structure ) {
    474         $link = trailingslashit(get_option('home')) . "?feed=$feed&author=" . $author_id;
     474        $link = home_url("?feed=$feed&author=" . $author_id);
    475475    } else {
    476476        $link = get_author_posts_url($author_id);
     
    516516
    517517    if ( '' == $permalink_structure ) {
    518         $link = trailingslashit(get_option('home')) . "?feed=$feed&cat=" . $cat_id;
     518        $link = home_url("?feed=$feed&cat=" . $cat_id);
    519519    } else {
    520520        $link = get_category_link($cat_id);
     
    555555
    556556    if ( '' == $permalink_structure ) {
    557         $link = trailingslashit(get_option('home')) . "?feed=$feed&tag=" . $tag->slug;
     557        $link = home_url("?feed=$feed&tag=" . $tag->slug);
    558558    } else {
    559559        $link = get_tag_link($tag->term_id);
     
    630630        $feed = get_default_feed();
    631631
    632     $link = trailingslashit(get_option('home')) . "?s=$search&feed=$feed";
     632    $link = home_url("?s=$search&feed=$feed");
    633633
    634634    $link = apply_filters('search_feed_link', $link);
     
    655655        $feed = get_default_feed();
    656656
    657     $link = trailingslashit(get_option('home')) . "?s=$search&feed=comments-$feed";
     657    $link = home_url("?s=$search&feed=comments-$feed");
    658658
    659659    $link = apply_filters('search_feed_link', $link);
     
    12761276    $request = remove_query_arg( 'paged' );
    12771277
    1278     $home_root = parse_url(get_option('home'));
     1278    $home_root = parse_url(home_url());
    12791279    $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
    12801280    $home_root = preg_quote( trailingslashit( $home_root ), '|' );
     
    17071707
    17081708    return apply_filters('shortcut_link', $link);
     1709}
     1710
     1711/**
     1712 * Retrieve the home url.
     1713 *
     1714 * Returns the 'home' option with the appropriate protocol,  'https' if
     1715 * is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
     1716 * overridden.
     1717 *
     1718 * @package WordPress
     1719 * @since 3.0
     1720 *
     1721 * @param  string $path   (optional) Path relative to the home url.
     1722 * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http','https'
     1723 * @return string Home url link with optional path appended.
     1724*/
     1725function home_url( $path = '', $scheme = null ) {
     1726    $orig_scheme = $scheme;
     1727    $scheme      = is_ssl() && !is_admin() ? 'https' : 'http';
     1728    $url = str_replace( 'http://', "$scheme://", get_option('home') );
     1729
     1730    if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     1731        $url .= '/' . ltrim( $path, '/' );
     1732
     1733    return apply_filters( 'home_url', $url, $path, $orig_scheme );
    17091734}
    17101735
Note: See TracChangeset for help on using the changeset viewer.