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

git-svn-id: http://core.svn.wordpress.org/trunk@21734 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-09-04 14:44:17 +00:00
parent 4c9e40f2bb
commit c1d2f4770d

View File

@ -1908,10 +1908,7 @@ function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
restore_current_blog();
}
if ( 'relative' == $scheme )
$url = preg_replace( '#^.+://[^/]*#', '', $url );
elseif ( 'http' != $scheme )
$url = str_replace( 'http://', "$scheme://", $url );
$url = set_url_scheme( $url, $scheme );
if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= '/' . ltrim( $path, '/' );
@ -1932,7 +1929,7 @@ function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
* @uses get_site_url()
*
* @param string $path Optional. Path relative to the site url.
* @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
* @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
* @return string Site url link with optional path appended.
*/
function site_url( $path = '', $scheme = null ) {
@ -1955,19 +1952,6 @@ function site_url( $path = '', $scheme = null ) {
* @return string Site url link with optional path appended.
*/
function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
// should the list of allowed schemes be maintained elsewhere?
$orig_scheme = $scheme;
if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
$scheme = 'https';
elseif ( ( 'login' == $scheme ) && force_ssl_admin() )
$scheme = 'https';
elseif ( ( 'admin' == $scheme ) && force_ssl_admin() )
$scheme = 'https';
else
$scheme = ( is_ssl() ? 'https' : 'http' );
}
if ( empty( $blog_id ) || !is_multisite() ) {
$url = get_option( 'siteurl' );
} else {
@ -1976,15 +1960,12 @@ function get_site_url( $blog_id = null, $path = '', $scheme = null ) {
restore_current_blog();
}
if ( 'relative' == $scheme )
$url = preg_replace( '#^.+://[^/]*#', '', $url );
elseif ( 'http' != $scheme )
$url = str_replace( 'http://', "{$scheme}://", $url );
$url = set_url_scheme( $url, $scheme );
if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= '/' . ltrim( $path, '/' );
return apply_filters( 'site_url', $url, $path, $orig_scheme, $blog_id );
return apply_filters( 'site_url', $url, $path, $scheme, $blog_id );
}
/**
@ -2107,7 +2088,7 @@ function plugins_url($path = '', $plugin = '') {
* @since 3.0.0
*
* @param string $path Optional. Path relative to the site url.
* @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
* @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
* @return string Site url link with optional path appended.
*/
function network_site_url( $path = '', $scheme = null ) {
@ -2116,27 +2097,15 @@ function network_site_url( $path = '', $scheme = null ) {
if ( ! is_multisite() )
return site_url($path, $scheme);
$orig_scheme = $scheme;
if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) {
if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) )
$scheme = 'https';
elseif ( ('login' == $scheme) && ( force_ssl_admin() ) )
$scheme = 'https';
elseif ( ('admin' == $scheme) && force_ssl_admin() )
$scheme = 'https';
else
$scheme = ( is_ssl() ? 'https' : 'http' );
}
if ( 'relative' == $scheme )
$url = $current_site->path;
else
$url = $scheme . '://' . $current_site->domain . $current_site->path;
$url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= ltrim( $path, '/' );
return apply_filters('network_site_url', $url, $path, $orig_scheme);
return apply_filters( 'network_site_url', $url, $path, $scheme );
}
/**
@ -2167,7 +2136,7 @@ function network_home_url( $path = '', $scheme = null ) {
if ( 'relative' == $scheme )
$url = $current_site->path;
else
$url = $scheme . '://' . $current_site->domain . $current_site->path;
$url = set_url_scheme( 'http://' . $current_site->domain . $current_site->path, $scheme );
if ( ! empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
$url .= ltrim( $path, '/' );