Index: wp-signup.php
===================================================================
--- wp-signup.php	(revision 21628)
+++ wp-signup.php	(working copy)
@@ -390,11 +390,7 @@
 if ( $active_signup == 'none' ) {
 	_e( 'Registration has been disabled.' );
 } elseif ( $active_signup == 'blog' && !is_user_logged_in() ) {
-	if ( is_ssl() )
-		$proto = 'https://';
-	else
-		$proto = 'http://';
-	$login_url = site_url( 'wp-login.php?redirect_to=' . urlencode($proto . $_SERVER['HTTP_HOST'] . '/wp-signup.php' ));
+	$login_url = site_url( 'wp-login.php?redirect_to=' . urlencode( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . '/wp-signup.php' ) ) );
 	echo sprintf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
 } else {
 	$stage = isset( $_POST['stage'] ) ?  $_POST['stage'] : 'default';
Index: wp-login.php
===================================================================
--- wp-login.php	(revision 21628)
+++ wp-login.php	(working copy)
@@ -12,12 +12,12 @@
 require( dirname(__FILE__) . '/wp-load.php' );
 
 // Redirect to https login if forced to use SSL
-if ( force_ssl_admin() && !is_ssl() ) {
+if ( force_ssl_admin() && ! is_ssl() ) {
 	if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
-		wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
+		wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
 		exit();
 	} else {
-		wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+		wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 		exit();
 	}
 }
@@ -365,9 +365,9 @@
 	if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
 		$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
 
-	$schema = is_ssl() ? 'https://' : 'http://';
-	if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') )
-		update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) );
+	$url = dirname( set_url_scheme( 'http://' .  $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
+	if ( $url != get_option( 'siteurl' ) )
+		update_option( 'siteurl', $url );
 }
 
 //Set a cookie now to see if they are supported by the browser.
Index: wp-includes/nav-menu-template.php
===================================================================
--- wp-includes/nav-menu-template.php	(revision 21628)
+++ wp-includes/nav-menu-template.php	(working copy)
@@ -358,7 +358,7 @@
 		// if the menu item corresponds to the currently-requested URL
 		} elseif ( 'custom' == $menu_item->object ) {
 			$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
-			$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_root_relative_current;
+			$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
 			$raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
 			$item_url = untrailingslashit( $raw_item_url );
 			$_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) );
Index: wp-includes/theme.php
===================================================================
--- wp-includes/theme.php	(revision 21628)
+++ wp-includes/theme.php	(working copy)
@@ -891,12 +891,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 );
-
-	return esc_url_raw( $url );
+	return esc_url_raw( set_url_scheme( $url ) );
 }
 
 /**
Index: wp-includes/functions.php
===================================================================
--- wp-includes/functions.php	(revision 21628)
+++ wp-includes/functions.php	(working copy)
@@ -2933,12 +2933,11 @@
  * @return string
  */
 function wp_guess_url() {
-	if ( defined('WP_SITEURL') && '' != WP_SITEURL ) {
+	if ( defined('WP_SITEURL') && '' != WP_SITEURL )
 		$url = WP_SITEURL;
-	} else {
-		$schema = is_ssl() ? 'https://' : 'http://';
-		$url = preg_replace('#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
-	}
+	else
+		$url = set_url_scheme( preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
+
 	return rtrim($url, '/');
 }
 
Index: wp-includes/class-wp-xmlrpc-server.php
===================================================================
--- wp-includes/class-wp-xmlrpc-server.php	(revision 21628)
+++ wp-includes/class-wp-xmlrpc-server.php	(working copy)
@@ -3221,9 +3221,8 @@
 		global $current_blog;
 		$domain = $current_blog->domain;
 		$path = $current_blog->path . 'xmlrpc.php';
-		$protocol = is_ssl() ? 'https' : 'http';
 
-		$rpc = new IXR_Client("$protocol://{$domain}{$path}");
+		$rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) );
 		$rpc->query('wp.getUsersBlogs', $args[1], $args[2]);
 		$blogs = $rpc->getResponse();
 
Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 21628)
+++ wp-includes/link-template.php	(working copy)
@@ -2049,9 +2049,7 @@
  * @return string Content url link with optional path appended.
 */
 function content_url($path = '') {
-	$url = WP_CONTENT_URL;
-	if ( 0 === strpos($url, 'http') && is_ssl() )
-		$url = str_replace( 'http://', 'https://', $url );
+	$url = set_url_scheme( WP_CONTENT_URL );
 
 	if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
 		$url .= '/' . ltrim($path, '/');
@@ -2083,8 +2081,8 @@
 	else
 		$url = WP_PLUGIN_URL;
 
-	if ( 0 === strpos($url, 'http') && is_ssl() )
-		$url = str_replace( 'http://', 'https://', $url );
+	
+	$url = set_url_scheme( $url );
 
 	if ( !empty($plugin) && is_string($plugin) ) {
 		$folder = dirname(plugin_basename($plugin));
Index: wp-includes/pluggable.php
===================================================================
--- wp-includes/pluggable.php	(revision 21628)
+++ wp-includes/pluggable.php	(working copy)
@@ -748,11 +748,11 @@
 
 	// If https is required and request is http, redirect
 	if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
-		if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
-			wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
+		if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
+			wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
 			exit();
 		} else {
-			wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+			wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 			exit();
 		}
 	}
@@ -767,11 +767,11 @@
 
 		// If the user wants ssl but the session is not ssl, redirect.
 		if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
-			if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
-				wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
+			if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
+				wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
 				exit();
 			} else {
-				wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+				wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 				exit();
 			}
 		}
@@ -782,13 +782,8 @@
 	// The cookie is no good so force login
 	nocache_headers();
 
-	if ( is_ssl() )
-		$proto = 'https://';
-	else
-		$proto = 'http://';
+	$redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 
-	$redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
-
 	$login_url = wp_login_url($redirect, true);
 
 	wp_redirect($login_url);
Index: wp-includes/feed.php
===================================================================
--- wp-includes/feed.php	(revision 21628)
+++ wp-includes/feed.php	(working copy)
@@ -488,12 +488,7 @@
  */
 function self_link() {
 	$host = @parse_url(home_url());
-	$host = $host['host'];
-	echo esc_url(
-		( is_ssl() ? 'https' : 'http' ) . '://'
-		. $host
-		. stripslashes($_SERVER['REQUEST_URI'])
-		);
+	echo esc_url( set_url_scheme( 'http://' . $host['host'] . stripslashes($_SERVER['REQUEST_URI']) ) );
 }
 
 /**
Index: wp-includes/ms-functions.php
===================================================================
--- wp-includes/ms-functions.php	(revision 21628)
+++ wp-includes/ms-functions.php	(working copy)
@@ -1875,22 +1875,22 @@
 }
 
 /**
- * Formats an String URL to use HTTPS if HTTP is found.
+ * Formats a URL to use https.
+ * 
  * Useful as a filter.
  *
  * @since 2.8.5
- **/
+ *
+ * @param string URL
+ * @return string URL with https as the scheme
+ */
 function filter_SSL( $url ) {
-	if ( !is_string( $url ) )
-		return get_bloginfo( 'url' ); //return home blog url with proper scheme
+	if ( ! is_string( $url ) )
+		return get_bloginfo( 'url' ); // Return home blog url with proper scheme
 
-	$arrURL = parse_url( $url );
+	if ( force_ssl_content() && is_ssl() )
+		$url = set_url_scheme( $url, 'https' );
 
-	if ( force_ssl_content() && is_ssl() ) {
-		if ( 'http' === $arrURL['scheme'] )
-			$url = str_replace( $arrURL['scheme'], 'https', $url );
-	}
-
 	return $url;
 }
 
Index: wp-admin/includes/plugin.php
===================================================================
--- wp-admin/includes/plugin.php	(revision 21628)
+++ wp-admin/includes/plugin.php	(working copy)
@@ -903,8 +903,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);
+	else
+		$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-admin/includes/class-wp-list-table.php
===================================================================
--- wp-admin/includes/class-wp-list-table.php	(revision 21628)
+++ wp-admin/includes/class-wp-list-table.php	(working copy)
@@ -490,7 +490,7 @@
 
 		$current = $this->get_pagenum();
 
-		$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+		$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 
 		$current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
 
@@ -651,7 +651,7 @@
 
 		list( $columns, $hidden, $sortable ) = $this->get_column_info();
 
-		$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+		$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 		$current_url = remove_query_arg( 'paged', $current_url );
 
 		if ( isset( $_GET['orderby'] ) )
Index: wp-admin/includes/meta-boxes.php
===================================================================
--- wp-admin/includes/meta-boxes.php	(revision 21628)
+++ wp-admin/includes/meta-boxes.php	(working copy)
@@ -41,9 +41,7 @@
 	$preview_link = esc_url( get_permalink( $post->ID ) );
 	$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( get_permalink( $post->ID ) );
 	$preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) );
 	$preview_button = __( 'Preview' );
 }
