From 58183047084749e835a55d3e05f19fc464eb1fa3 Mon Sep 17 00:00:00 2001
From: Nikita Youshchenko <yoush@debian.org>
Date: Sat, 8 Jan 2011 15:01:21 +0300
Subject: [PATCH] When converting http url to https url, remove port
If wordpress base url contains port setting, such as
http://yoush.homelinux.org:8079/
and ADMIN_FORCE_SSL is enabled, wordpress generates links starting
with
https://yoush.homelinux.org:8079/
which is always incorrect since it is impossible to serve http and
https on the same port.
This patch attempts to remove port setting from URL when converting
http url to https url.
Signed-off-by: Nikita Youshchenko <yoush@debian.org>
---
wp-admin/includes/plugin.php | 2 +-
wp-admin/includes/post.php | 2 +-
wp-admin/themes.php | 2 +-
wp-includes/link-template.php | 5 ++++-
wp-login.php | 6 +++---
5 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php
index 98ee2a1..d496a01 100644
a
|
b
|
function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $func |
831 | 831 | if ( empty($icon_url) ) |
832 | 832 | $icon_url = esc_url( admin_url( 'images/generic.png' ) ); |
833 | 833 | elseif ( is_ssl() && 0 === strpos($icon_url, 'http://') ) |
834 | | $icon_url = 'https://' . substr($icon_url, 7); |
| 834 | $icon_url = preg_replace( '|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $icon_url ); |
835 | 835 | |
836 | 836 | $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); |
837 | 837 | |
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index 6448c9e..1770ee0 100644
a
|
b
|
function wp_tiny_mce( $teeny = false, $settings = false ) { |
1400 | 1400 | |
1401 | 1401 | foreach ( $mce_external_plugins as $name => $url ) { |
1402 | 1402 | |
1403 | | if ( is_ssl() ) $url = str_replace('http://', 'https://', $url); |
| 1403 | if ( is_ssl() ) $url = preg_replace('|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $url); |
1404 | 1404 | |
1405 | 1405 | $plugins[] = '-' . $name; |
1406 | 1406 | |
diff --git a/wp-admin/themes.php b/wp-admin/themes.php
index 7258932..1398184 100644
a
|
b
|
foreach ( $cols as $col => $theme_name ) { |
183 | 183 | $theme_root_uri = $themes[$theme_name]['Theme Root URI']; |
184 | 184 | $preview_link = esc_url(get_option('home') . '/'); |
185 | 185 | if ( is_ssl() ) |
186 | | $preview_link = str_replace( 'http://', 'https://', $preview_link ); |
| 186 | $preview_link = preg_replace( '|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $preview_link ); |
187 | 187 | $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) ); |
188 | 188 | $preview_text = esc_attr( sprintf( __('Preview of “%s”'), $title ) ); |
189 | 189 | $tags = $themes[$theme_name]['Tags']; |
diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php
index a800da8..85d712d 100644
a
|
b
|
function get_site_url( $blog_id = null, $path = '', $scheme = null ) { |
1925 | 1925 | else |
1926 | 1926 | $url = get_blog_option( $blog_id, 'siteurl' ); |
1927 | 1927 | |
| 1928 | if ( ( 'https' == $scheme ) && preg_match( '|http://[^/:]+:|', $url ) ) |
| 1929 | $url = preg_replace( '/:[0-9]+/', '', $url, 1 ); |
| 1930 | |
1928 | 1931 | $url = str_replace( 'http://', "{$scheme}://", $url ); |
1929 | 1932 | |
1930 | 1933 | if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) |
… |
… |
function includes_url($path = '') { |
1997 | 2000 | function content_url($path = '') { |
1998 | 2001 | $url = WP_CONTENT_URL; |
1999 | 2002 | if ( 0 === strpos($url, 'http') && is_ssl() ) |
2000 | | $url = str_replace( 'http://', 'https://', $url ); |
| 2003 | $url = preg_replace('|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $url ); |
2001 | 2004 | |
2002 | 2005 | if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
2003 | 2006 | $url .= '/' . ltrim($path, '/'); |
diff --git a/wp-login.php b/wp-login.php
index c97edd9..d480220 100644
a
|
b
|
require( dirname(__FILE__) . '/wp-load.php' ); |
14 | 14 | // Redirect to https login if forced to use SSL |
15 | 15 | if ( force_ssl_admin() && !is_ssl() ) { |
16 | 16 | if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { |
17 | | wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); |
| 17 | wp_redirect(preg_replace('|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $_SERVER['REQUEST_URI'])); |
18 | 18 | exit(); |
19 | 19 | } else { |
20 | | wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
| 20 | wp_redirect('https://' . preg_replace(':[0-9]+', '', $_SERVER['HTTP_HOST']) . $_SERVER['REQUEST_URI']); |
21 | 21 | exit(); |
22 | 22 | } |
23 | 23 | } |
… |
… |
default: |
518 | 518 | $redirect_to = $_REQUEST['redirect_to']; |
519 | 519 | // Redirect to https if user wants ssl |
520 | 520 | if ( $secure_cookie && false !== strpos($redirect_to, 'wp-admin') ) |
521 | | $redirect_to = preg_replace('|^http://|', 'https://', $redirect_to); |
| 521 | $redirect_to = preg_replace('|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $redirect_to); |
522 | 522 | } else { |
523 | 523 | $redirect_to = admin_url(); |
524 | 524 | } |