WordPress.org

Make WordPress Core

Changeset 19870


Ignore:
Timestamp:
02/08/2012 04:09:41 PM (8 years ago)
Author:
nacin
Message:

Introduce 'relative' scheme to return only the paths for home_url, site, admin, network_, and get_ variants. props SergeyBiryukov, see #18952.

File:
1 edited

Legend:

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

    r19712 r19870  
    18351835 *
    18361836 * @param  string $path   (optional) Path relative to the home url.
    1837  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https'.
     1837 * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
    18381838 * @return string Home url link with optional path appended.
    18391839*/
     
    18541854 * @param  int $blog_id   (optional) Blog ID. Defaults to current blog.
    18551855 * @param  string $path   (optional) Path relative to the home url.
    1856  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https'.
     1856 * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
    18571857 * @return string Home url link with optional path appended.
    18581858*/
     
    18601860    $orig_scheme = $scheme;
    18611861
    1862     if ( !in_array( $scheme, array( 'http', 'https' ) ) )
     1862    if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
    18631863        $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
    18641864
     
    18681868        $url = get_blog_option( $blog_id, 'home' );
    18691869
    1870     if ( 'http' != $scheme )
     1870    if ( 'relative' == $scheme )
     1871        $url = preg_replace( '#^.+://[^/]*#', '', $url );
     1872    elseif ( 'http' != $scheme )
    18711873        $url = str_replace( 'http://', "$scheme://", $url );
    18721874
     
    18901892 *
    18911893 * @param string $path Optional. Path relative to the site url.
    1892  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', or 'admin'.
     1894 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
    18931895 * @return string Site url link with optional path appended.
    18941896*/
     
    19091911 * @param int $blog_id (optional) Blog ID. Defaults to current blog.
    19101912 * @param string $path Optional. Path relative to the site url.
    1911  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', or 'admin'.
     1913 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
    19121914 * @return string Site url link with optional path appended.
    19131915*/
     
    19151917    // should the list of allowed schemes be maintained elsewhere?
    19161918    $orig_scheme = $scheme;
    1917     if ( !in_array( $scheme, array( 'http', 'https' ) ) ) {
     1919    if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
    19181920        if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
    19191921            $scheme = 'https';
     
    19311933        $url = get_blog_option( $blog_id, 'siteurl' );
    19321934
    1933     if ( 'http' != $scheme )
     1935    if ( 'relative' == $scheme )
     1936        $url = preg_replace( '#^.+://[^/]*#', '', $url );
     1937    elseif ( 'http' != $scheme )
    19341938        $url = str_replace( 'http://', "{$scheme}://", $url );
    19351939
     
    20622066 *
    20632067 * @param string $path Optional. Path relative to the site url.
    2064  * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', or 'admin'.
     2068 * @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
    20652069 * @return string Site url link with optional path appended.
    20662070*/
     
    20722076
    20732077    $orig_scheme = $scheme;
    2074     if ( !in_array($scheme, array('http', 'https')) ) {
     2078    if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
    20752079        if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
    20762080            $scheme = 'https';
     
    20832087    }
    20842088
    2085     $url = $scheme . '://' . $current_site->domain . $current_site->path;
     2089    if ( 'relative' == $scheme )
     2090        $url = $current_site->path;
     2091    else
     2092        $url = $scheme . '://' . $current_site->domain . $current_site->path;
    20862093
    20872094    if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
     
    21022109 *
    21032110 * @param  string $path   (optional) Path relative to the home url.
    2104  * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https'.
     2111 * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
    21052112 * @return string Home url link with optional path appended.
    21062113*/
     
    21132120    $orig_scheme = $scheme;
    21142121
    2115     if ( !in_array($scheme, array('http', 'https')) )
     2122    if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
    21162123        $scheme = is_ssl() && !is_admin() ? 'https' : 'http';
    21172124
    2118     $url = $scheme . '://' . $current_site->domain . $current_site->path;
     2125    if ( 'relative' == $scheme )
     2126        $url = $current_site->path;
     2127    else
     2128        $url = $scheme . '://' . $current_site->domain . $current_site->path;
    21192129
    21202130    if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
Note: See TracChangeset for help on using the changeset viewer.