Introduce set_url_scheme(). Includes get_site_url() logic for determining when to use http vs. https. Use this to rerite urls to obey is_ssl(). Props jkudish. fixes #18017

git-svn-id: http://core.svn.wordpress.org/trunk@20828 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2012-05-18 20:04:59 +00:00
parent eb09282a9c
commit 46e4ffe765
1 changed files with 30 additions and 0 deletions

View File

@ -2197,6 +2197,36 @@ function self_admin_url($path = '', $scheme = 'admin') {
return admin_url($path, $scheme); return admin_url($path, $scheme);
} }
/**
* Set the scheme for a URL
*
* @since 3.4.0
*
* @param string $url Absolute url that includes a scheme
* @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'.
* @return string $url URL with chosen scheme.
*/
function set_url_scheme( $url, $scheme = null ) {
$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 = preg_replace( '#^.+://[^/]*#', '', $url );
else
$url = preg_replace( '#^.+://#', $scheme . '://', $url );
return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme );
}
/** /**
* Get the URL to the user's dashboard. * Get the URL to the user's dashboard.
* *