Message info
 
To:wp-svn@lists.automattic.com From:m@wordpress.org Subject:[wp-svn] [20828] trunk/wp-includes/link-template.php: Introduce set_url_scheme(). Date:Fri, 18 May 2012 20:04:59 +0000 (UTC)
 

Revision
20828
Author
ryan
Date
2012-05-18 20:04:59 +0000 (Fri, 18 May 2012)

Log Message

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

Modified Paths

Diff

Modified: trunk/wp-includes/link-template.php (20827 => 20828)


--- trunk/wp-includes/link-template.php	2012-05-18 16:27:24 UTC (rev 20827)
+++ trunk/wp-includes/link-template.php	2012-05-18 20:04:59 UTC (rev 20828)
@@ -2198,6 +2198,36 @@
 }
 
 /**
+ * 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.
  *
  * If a user does not belong to any site, the global user dashboard is used. If the user belongs to the current site,