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_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 @@ class WP_List_Table {
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'] ) )

View File

@ -41,9 +41,7 @@ if ( 'publish' == $post->post_status ) {
$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' );
}

View File

@ -903,8 +903,8 @@ function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func
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 );

View File

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

View File

@ -3221,9 +3221,8 @@ class wp_xmlrpc_server extends IXR_Server {
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();

View File

@ -488,12 +488,7 @@ function prep_atom_text_construct($data) {
*/
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']) ) );
}
/**

View File

@ -2585,8 +2585,8 @@ function absint( $maybeint ) {
*/
function url_is_accessable_via_ssl($url)
{
if (in_array('curl', get_loaded_extensions())) {
$ssl = preg_replace( '/^http:\/\//', 'https://', $url );
if ( in_array( 'curl', get_loaded_extensions() ) ) {
$ssl = set_url_scheme( $url, 'https' );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ssl);
@ -2933,12 +2933,11 @@ function force_ssl_admin( $force = null ) {
* @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, '/');
}

View File

@ -2049,9 +2049,7 @@ function includes_url($path = '') {
* @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 @@ function plugins_url($path = '', $plugin = '') {
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));

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.
*
* @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() ) {
if ( 'http' === $arrURL['scheme'] )
$url = str_replace( $arrURL['scheme'], 'https', $url );
}
if ( force_ssl_content() && is_ssl() )
$url = set_url_scheme( $url, 'https' );
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
} 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 ) );

View File

@ -748,11 +748,11 @@ function auth_redirect() {
// 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 @@ function auth_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 ( 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,12 +782,7 @@ function auth_redirect() {
// 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() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
$login_url = wp_login_url($redirect, true);

View File

@ -891,12 +891,7 @@ function get_header_image() {
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 ) );
}
/**

View File

@ -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 ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set
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.

View File

@ -390,11 +390,7 @@ $current_user = wp_get_current_user();
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';