Index: wp-admin/includes/meta-boxes.php
===================================================================
--- wp-admin/includes/meta-boxes.php	(revision 20941)
+++ wp-admin/includes/meta-boxes.php	(working copy)
@@ -42,8 +42,7 @@
 	$preview_button = __( 'Preview Changes' );
 } else {
 	$preview_link = get_permalink( $post->ID );
-	if ( is_ssl() )
-		$preview_link = str_replace( 'http://', 'https://', $preview_link );
+	$preview_link = set_url_scheme( $preview_link );
 	$preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) );
 	$preview_button = __( 'Preview' );
 }
Index: wp-admin/includes/plugin.php
===================================================================
--- wp-admin/includes/plugin.php	(revision 20941)
+++ wp-admin/includes/plugin.php	(working copy)
@@ -902,8 +902,8 @@
 
 	if ( empty($icon_url) )
 		$icon_url = esc_url( admin_url( 'images/generic.png' ) );
-	elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') )
-		$icon_url = 'https://' . substr($icon_url, 7);
+	elseif ( 0 === strpos($icon_url, 'http') )
+		$icon_url = set_url_scheme( $icon_url );
 
 	$new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
 
Index: wp-includes/class-wp-editor.php
===================================================================
--- wp-includes/class-wp-editor.php	(revision 20941)
+++ wp-includes/class-wp-editor.php	(working copy)
@@ -209,7 +209,7 @@
 
 						foreach ( $mce_external_plugins as $name => $url ) {
 
-							if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);
+							$url = set_url_scheme( $url );
 
 							$plugins[] = '-' . $name;
 
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 20941)
+++ wp-includes/functions.php	(working copy)
@@ -2649,7 +2649,7 @@
 function url_is_accessable_via_ssl($url)
 {
 	if (in_array('curl', get_loaded_extensions())) {
-		$ssl = preg_replace( '/^http:\/\//', 'https://',  $url );
+		$ssl = set_url_scheme( $url, 'https' );
 
 		$ch = curl_init();
 		curl_setopt($ch, CURLOPT_URL, $ssl);
Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 20941)
+++ wp-includes/link-template.php	(working copy)
@@ -1838,7 +1838,7 @@
  * @uses get_home_url()
  *
  * @param  string $path   (optional) Path relative to the home url.
- * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
+ * @param  string $scheme (optional) Scheme to give the home url context. See set_url_scheme().
  * @return string Home url link with optional path appended.
 */
 function home_url( $path = '', $scheme = null ) {
@@ -1857,29 +1857,22 @@
  *
  * @param  int $blog_id   (optional) Blog ID. Defaults to current blog.
  * @param  string $path   (optional) Path relative to the home url.
- * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
+ * @param  string $scheme (optional) Scheme to give the home url context. See set_url_scheme().
  * @return string Home url link with optional path appended.
 */
 function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
-	$orig_scheme = $scheme;
 
-	if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
-		$scheme = is_ssl() && !is_admin() ? 'https' : 'http';
-
 	if ( empty( $blog_id ) || !is_multisite() )
 		$url = get_option( 'home' );
 	else
 		$url = get_blog_option( $blog_id, 'home' );
 
-	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( 'home_url', $url, $path, $orig_scheme, $blog_id );
+	return apply_filters( 'home_url', $url, $path, $scheme, $blog_id );
 }
 
 /**
@@ -1895,7 +1888,7 @@
  * @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 ) {
@@ -1914,37 +1907,22 @@
  *
  * @param int $blog_id (optional) Blog ID. Defaults to current blog.
  * @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 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
 		$url = get_blog_option( $blog_id, 'siteurl' );
 
-	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 );
 }
 
 /**
@@ -2010,8 +1988,8 @@
 */
 function content_url($path = '') {
 	$url = WP_CONTENT_URL;
-	if ( 0 === strpos($url, 'http') && is_ssl() )
-		$url = str_replace( 'http://', 'https://', $url );
+	if ( 0 === strpos($url, 'http') )
+		$url = set_scheme_url( $url );
 
 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
 		$url .= '/' . ltrim($path, '/');
@@ -2043,8 +2021,8 @@
 	else
 		$url = WP_PLUGIN_URL;
 
-	if ( 0 === strpos($url, 'http') && is_ssl() )
-		$url = str_replace( 'http://', 'https://', $url );
+	if ( 0 === strpos($url, 'http') )
+		$url = set_url_scheme( $url );
 
 	if ( !empty($plugin) && is_string($plugin) ) {
 		$folder = dirname(plugin_basename($plugin));
@@ -2069,7 +2047,7 @@
  * @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 ) {
@@ -2078,27 +2056,15 @@
 	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);
 }
 
 /**
@@ -2112,7 +2078,7 @@
  * @since 3.0.0
  *
  * @param  string $path   (optional) Path relative to the home url.
- * @param  string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'.
+ * @param  string $scheme (optional) Scheme to give the home url context. See set_url_scheme().
  * @return string Home url link with optional path appended.
 */
 function network_home_url( $path = '', $scheme = null ) {
@@ -2121,20 +2087,15 @@
 	if ( !is_multisite() )
 		return home_url($path, $scheme);
 
-	$orig_scheme = $scheme;
-
-	if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) )
-		$scheme = is_ssl() && !is_admin() ? '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_home_url', $url, $path, $orig_scheme);
+	return apply_filters( 'network_home_url', $url, $path, $scheme);
 }
 
 /**
Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 20941)
+++ wp-includes/theme.php	(working copy)
@@ -869,10 +869,7 @@
 	if ( is_random_header_image() )
 		$url = get_random_header_image();
 
-	if ( is_ssl() )
-		$url = str_replace( 'http://', 'https://', $url );
-	else
-		$url = str_replace( 'https://', 'http://', $url );
+	$url = set_url_scheme( $url );
 
 	return esc_url_raw( $url );
 }
