Use set_url_scheme(). Props johnbillion, MarcusPope. see #19037 #20759

git-svn-id: http://core.svn.wordpress.org/trunk@21664 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-08-30 13:33:00 +00:00
parent e0835b5fc4
commit c55cf716da
14 changed files with 43 additions and 68 deletions

View File

@ -490,7 +490,7 @@ class WP_List_Table {
$current = $this->get_pagenum(); $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 ); $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
@ -651,7 +651,7 @@ class WP_List_Table {
list( $columns, $hidden, $sortable ) = $this->get_column_info(); 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 ); $current_url = remove_query_arg( 'paged', $current_url );
if ( isset( $_GET['orderby'] ) ) if ( isset( $_GET['orderby'] ) )

View File

@ -41,9 +41,7 @@ if ( 'publish' == $post->post_status ) {
$preview_link = esc_url( get_permalink( $post->ID ) ); $preview_link = esc_url( get_permalink( $post->ID ) );
$preview_button = __( 'Preview Changes' ); $preview_button = __( 'Preview Changes' );
} else { } else {
$preview_link = get_permalink( $post->ID ); $preview_link = set_url_scheme( get_permalink( $post->ID ) );
if ( is_ssl() )
$preview_link = str_replace( 'http://', 'https://', $preview_link );
$preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) ); $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) );
$preview_button = __( 'Preview' ); $preview_button = __( 'Preview' );
} }

View File

@ -903,8 +903,8 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func
if ( empty($icon_url) ) if ( empty($icon_url) )
$icon_url = esc_url( admin_url( 'images/generic.png' ) ); $icon_url = esc_url( admin_url( 'images/generic.png' ) );
elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) else
$icon_url = 'https://' . substr($icon_url, 7); $icon_url = set_url_scheme( $icon_url );
$new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );

View File

@ -211,7 +211,7 @@ final class _WP_Editors {
foreach ( $mce_external_plugins as $name => $url ) { foreach ( $mce_external_plugins as $name => $url ) {
if ( is_ssl() ) $url = str_replace('http://', 'https://', $url); $url = set_url_scheme( $url );
$plugins[] = '-' . $name; $plugins[] = '-' . $name;

View File

@ -3221,9 +3221,8 @@ class wp_xmlrpc_server extends IXR_Server {
global $current_blog; global $current_blog;
$domain = $current_blog->domain; $domain = $current_blog->domain;
$path = $current_blog->path . 'xmlrpc.php'; $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]); $rpc->query('wp.getUsersBlogs', $args[1], $args[2]);
$blogs = $rpc->getResponse(); $blogs = $rpc->getResponse();

View File

@ -488,12 +488,7 @@ function prep_atom_text_construct($data) {
*/ */
function self_link() { function self_link() {
$host = @parse_url(home_url()); $host = @parse_url(home_url());
$host = $host['host']; echo esc_url( set_url_scheme( 'http://' . $host['host'] . stripslashes($_SERVER['REQUEST_URI']) ) );
echo esc_url(
( is_ssl() ? 'https' : 'http' ) . '://'
. $host
. stripslashes($_SERVER['REQUEST_URI'])
);
} }
/** /**

View File

@ -2586,7 +2586,7 @@ function absint( $maybeint ) {
function url_is_accessable_via_ssl($url) function url_is_accessable_via_ssl($url)
{ {
if ( in_array( 'curl', get_loaded_extensions() ) ) { if ( in_array( 'curl', get_loaded_extensions() ) ) {
$ssl = preg_replace( '/^http:\/\//', 'https://', $url ); $ssl = set_url_scheme( $url, 'https' );
$ch = curl_init(); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ssl); curl_setopt($ch, CURLOPT_URL, $ssl);
@ -2933,12 +2933,11 @@ function force_ssl_admin( $force = null ) {
* @return string * @return string
*/ */
function wp_guess_url() { function wp_guess_url() {
if ( defined('WP_SITEURL') && '' != WP_SITEURL ) { if ( defined('WP_SITEURL') && '' != WP_SITEURL )
$url = WP_SITEURL; $url = WP_SITEURL;
} else { else
$schema = is_ssl() ? 'https://' : 'http://'; $url = set_url_scheme( preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
$url = preg_replace('#/(wp-admin/.*|wp-login.php)#i', '', $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
return rtrim($url, '/'); return rtrim($url, '/');
} }

View File

@ -2049,9 +2049,7 @@ function includes_url($path = '') {
* @return string Content url link with optional path appended. * @return string Content url link with optional path appended.
*/ */
function content_url($path = '') { function content_url($path = '') {
$url = WP_CONTENT_URL; $url = set_url_scheme( WP_CONTENT_URL );
if ( 0 === strpos($url, 'http') && is_ssl() )
$url = str_replace( 'http://', 'https://', $url );
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
$url .= '/' . ltrim($path, '/'); $url .= '/' . ltrim($path, '/');
@ -2083,8 +2081,8 @@ function plugins_url($path = '', $plugin = '') {
else else
$url = WP_PLUGIN_URL; $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) ) { if ( !empty($plugin) && is_string($plugin) ) {
$folder = dirname(plugin_basename($plugin)); $folder = dirname(plugin_basename($plugin));

View File

@ -1875,21 +1875,21 @@ function force_ssl_content( $force = '' ) {
} }
/** /**
* Formats an String URL to use HTTPS if HTTP is found. * Formats a URL to use https.
*
* Useful as a filter. * Useful as a filter.
* *
* @since 2.8.5 * @since 2.8.5
**/ *
* @param string URL
* @return string URL with https as the scheme
*/
function filter_SSL( $url ) { function filter_SSL( $url ) {
if ( ! is_string( $url ) ) if ( ! is_string( $url ) )
return get_bloginfo( 'url' ); //return home blog url with proper scheme 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; return $url;
} }

View File

@ -358,7 +358,7 @@ function _wp_menu_item_classes_by_context( &$menu_items ) {
// if the menu item corresponds to the currently-requested URL // if the menu item corresponds to the currently-requested URL
} elseif ( 'custom' == $menu_item->object ) { } elseif ( 'custom' == $menu_item->object ) {
$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); $_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; $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 ); $item_url = untrailingslashit( $raw_item_url );
$_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) );

View File

@ -749,7 +749,7 @@ function auth_redirect() {
// If https is required and request is http, redirect // If https is required and request is http, redirect
if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { 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(); exit();
} else { } else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
@ -768,7 +768,7 @@ function auth_redirect() {
// If the user wants ssl but the session is not ssl, redirect. // 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 ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { 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(); exit();
} else { } else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
@ -782,12 +782,7 @@ function auth_redirect() {
// The cookie is no good so force login // The cookie is no good so force login
nocache_headers(); nocache_headers();
if ( is_ssl() ) $redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$proto = 'https://';
else
$proto = 'http://';
$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); $login_url = wp_login_url($redirect, true);

View File

@ -891,12 +891,7 @@ function get_header_image() {
if ( is_random_header_image() ) if ( is_random_header_image() )
$url = get_random_header_image(); $url = get_random_header_image();
if ( is_ssl() ) return esc_url_raw( set_url_scheme( $url ) );
$url = str_replace( 'http://', 'https://', $url );
else
$url = str_replace( 'https://', 'http://', $url );
return esc_url_raw( $url );
} }
/** /**

View File

@ -14,7 +14,7 @@ require( dirname(__FILE__) . '/wp-load.php' );
// Redirect to https login if forced to use SSL // 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') ) { 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(); exit();
} else { } else {
wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
@ -365,9 +365,9 @@ if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set
if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) ) if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
$_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] ); $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
$schema = is_ssl() ? 'https://' : 'http://'; $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
if ( dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) != get_option('siteurl') ) if ( $url != get_option( 'siteurl' ) )
update_option('siteurl', dirname($schema . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']) ); update_option( 'siteurl', $url );
} }
//Set a cookie now to see if they are supported by the browser. //Set a cookie now to see if they are supported by the browser.

View File

@ -390,11 +390,7 @@ $current_user = wp_get_current_user();
if ( $active_signup == 'none' ) { if ( $active_signup == 'none' ) {
_e( 'Registration has been disabled.' ); _e( 'Registration has been disabled.' );
} elseif ( $active_signup == 'blog' && !is_user_logged_in() ) { } elseif ( $active_signup == 'blog' && !is_user_logged_in() ) {
if ( is_ssl() ) $login_url = site_url( 'wp-login.php?redirect_to=' . urlencode( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . '/wp-signup.php' ) ) );
$proto = 'https://';
else
$proto = 'http://';
$login_url = site_url( 'wp-login.php?redirect_to=' . urlencode($proto . $_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 ); echo sprintf( __( 'You must first <a href="%s">log in</a>, and then you can create a new site.' ), $login_url );
} else { } else {
$stage = isset( $_POST['stage'] ) ? $_POST['stage'] : 'default'; $stage = isset( $_POST['stage'] ) ? $_POST['stage'] : 'default';