Make WordPress Core

Changeset 21734


Ignore:
Timestamp:
09/04/2012 02:44:17 PM (14 years ago)
Author:
ryan
Message:

Use set_url_scheme() in the *_url() functions to keep things DRY. Props johnbillion. fixes #20759

File:
1 edited

Legend:

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

    r21664 r21734  
    18771877*/
    18781878function home_url( $path = '', $scheme = null ) {
    1879         return get_home_url(null, $path, $scheme);
     1879        return get_home_url( null, $path, $scheme );
    18801880}
    18811881
     
    18981898        $orig_scheme = $scheme;
    18991899
    1900         if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
     1900        if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
    19011901                $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
    19021902
     
    19091909        }
    19101910
    1911         if ( 'relative' == $scheme )
    1912                 $url = preg_replace( '#^.+://[^/]*#', '', $url );
    1913         elseif ( 'http' != $scheme )
    1914                 $url = str_replace( 'http://', "$scheme://", $url );
    1915 
    1916         if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     1911        $url = set_url_scheme( $url, $scheme );
     1912
     1913        if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
    19171914                $url .= '/' . ltrim( $path, '/' );
    19181915
     
    19331930 *
    19341931 * @param string $path Optional. Path relative to the site url.
    1935  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
     1932 * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
    19361933 * @return string Site url link with optional path appended.
    19371934*/
    19381935function site_url( $path = '', $scheme = null ) {
    1939         return get_site_url(null, $path, $scheme);
     1936        return get_site_url( null, $path, $scheme );
    19401937}
    19411938
     
    19561953*/
    19571954function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
    1958         // should the list of allowed schemes be maintained elsewhere?
    1959         $orig_scheme = $scheme;
    1960         if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
    1961                 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
    1962                         $scheme = 'https';
    1963                 elseif ( ( 'login' == $scheme ) && force_ssl_admin() )
    1964                         $scheme = 'https';
    1965                 elseif ( ( 'admin' == $scheme ) && force_ssl_admin() )
    1966                         $scheme = 'https';
    1967                 else
    1968                         $scheme = ( is_ssl() ? 'https' : 'http' );
    1969         }
    1970 
    19711955        if ( empty( $blog_id ) || !is_multisite() ) {
    19721956                $url = get_option( 'siteurl' );
     
    19771961        }
    19781962
    1979         if ( 'relative' == $scheme )
    1980                 $url = preg_replace( '#^.+://[^/]*#', '', $url );
    1981         elseif ( 'http' != $scheme )
    1982                 $url = str_replace( 'http://', "{$scheme}://", $url );
    1983 
    1984         if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     1963        $url = set_url_scheme( $url, $scheme );
     1964
     1965        if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
    19851966                $url .= '/' . ltrim( $path, '/' );
    19861967
    1987         return apply_filters( 'site_url', $url, $path, $orig_scheme, $blog_id );
     1968        return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
    19881969}
    19891970
     
    19991980*/
    20001981function admin_url( $path = '', $scheme = 'admin' ) {
    2001         return get_admin_url(null, $path, $scheme);
     1982        return get_admin_url( null, $path, $scheme );
    20021983}
    20031984
     
    20161997        $url = get_site_url($blog_id, 'wp-admin/', $scheme);
    20171998
    2018         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
    2019                 $url .= ltrim($path, '/');
    2020 
    2021         return apply_filters('admin_url', $url, $path, $blog_id);
     1999        if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     2000                $url .= ltrim( $path, '/' );
     2001
     2002        return apply_filters( 'admin_url', $url, $path, $blog_id );
    20222003}
    20232004
     
    21082089 *
    21092090 * @param string $path Optional. Path relative to the site url.
    2110  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
     2091 * @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
    21112092 * @return string Site url link with optional path appended.
    21122093*/
     
    21142095        global $current_site;
    21152096
    2116         if ( !is_multisite() )
     2097        if ( ! is_multisite() )
    21172098                return site_url($path, $scheme);
    2118 
    2119         $orig_scheme = $scheme;
    2120         if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
    2121                 if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
    2122                         $scheme = 'https';
    2123                 elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
    2124                         $scheme = 'https';
    2125                 elseif ( ('admin' == $scheme) && force_ssl_admin() )
    2126                         $scheme = 'https';
    2127                 else
    2128                         $scheme = ( is_ssl() ? 'https' : 'http' );
    2129         }
    21302099
    21312100        if ( 'relative' == $scheme )
    21322101                $url = $current_site->path;
    21332102        else
    2134                 $url = $scheme . '://' . $current_site->domain . $current_site->path;
    2135 
    2136         if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
    2137                 $url .= ltrim($path, '/');
    2138 
    2139         return apply_filters('network_site_url', $url, $path, $orig_scheme);
     2103                $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
     2104
     2105        if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     2106                $url .= ltrim( $path, '/' );
     2107
     2108        return apply_filters( 'network_site_url', $url, $path, $scheme );
    21402109}
    21412110
     
    21572126        global $current_site;
    21582127
    2159         if ( !is_multisite() )
     2128        if ( ! is_multisite() )
    21602129                return home_url($path, $scheme);
    21612130
    21622131        $orig_scheme = $scheme;
    21632132
    2164         if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
    2165                 $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
     2133        if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
     2134                $scheme = is_ssl() && ! is_admin() ? 'https' : 'http';
    21662135
    21672136        if ( 'relative' == $scheme )
    21682137                $url = $current_site->path;
    21692138        else
    2170                 $url = $scheme . '://' . $current_site->domain . $current_site->path;
    2171 
    2172         if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
     2139                $url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
     2140
     2141        if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
    21732142                $url .= ltrim( $path, '/' );
    21742143
Note: See TracChangeset for help on using the changeset viewer.