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. *