From 46e4ffe7655ab96d0ef76fa7f903e729cc81c910 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 18 May 2012 20:04:59 +0000 Subject: [PATCH] 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 --- wp-includes/link-template.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index d0d62f22a..859610377 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -2197,6 +2197,36 @@ function self_admin_url($path = '', $scheme = 'admin') { 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. *