Make WordPress Core

Ticket #16167: When-converting-http-url-to-https-url-remove-port.patch

File When-converting-http-url-to-https-url-remove-port.patch, 5.0 KB (added by yoush, 14 years ago)

Patch that fixes this issue for me

  • wp-admin/includes/plugin.php

    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 
    831831        if ( empty($icon_url) )
    832832                $icon_url = esc_url( admin_url( 'images/generic.png' ) );
    833833        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 );
    835835
    836836        $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url );
    837837
  • wp-admin/includes/post.php

    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 ) { 
    14001400
    14011401                        foreach ( $mce_external_plugins as $name => $url ) {
    14021402
    1403                                 if ( is_ssl() ) $url = str_replace('http://', 'https://', $url);
     1403                                if ( is_ssl() ) $url = preg_replace('|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $url);
    14041404
    14051405                                $plugins[] = '-' . $name;
    14061406
  • wp-admin/themes.php

    diff --git a/wp-admin/themes.php b/wp-admin/themes.php
    index 7258932..1398184 100644
    a b foreach ( $cols as $col => $theme_name ) { 
    183183        $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
    184184        $preview_link = esc_url(get_option('home') . '/');
    185185        if ( is_ssl() )
    186                 $preview_link = str_replace( 'http://', 'https://', $preview_link );
     186                $preview_link = preg_replace( '|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $preview_link );
    187187        $preview_link = htmlspecialchars( add_query_arg( array('preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'TB_iframe' => 'true' ), $preview_link ) );
    188188        $preview_text = esc_attr( sprintf( __('Preview of &#8220;%s&#8221;'), $title ) );
    189189        $tags = $themes[$theme_name]['Tags'];
  • wp-includes/link-template.php

    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 ) { 
    19251925        else
    19261926                $url = get_blog_option( $blog_id, 'siteurl' );
    19271927
     1928        if ( ( 'https' == $scheme ) && preg_match( '|http://[^/:]+:|', $url ) )
     1929                $url = preg_replace( '/:[0-9]+/', '', $url, 1 );
     1930
    19281931        $url = str_replace( 'http://', "{$scheme}://", $url );
    19291932
    19301933        if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false )
    function includes_url($path = '') { 
    19972000function content_url($path = '') {
    19982001        $url = WP_CONTENT_URL;
    19992002        if ( 0 === strpos($url, 'http') && is_ssl() )
    2000                 $url = str_replace( 'http://', 'https://', $url );
     2003                $url = preg_replace('|^http://([^/:]+)(:[0-9]+)?|', 'https://${1}', $url );
    20012004
    20022005        if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
    20032006                $url .= '/' . ltrim($path, '/');
  • wp-login.php

    diff --git a/wp-login.php b/wp-login.php
    index c97edd9..d480220 100644
    a b require( dirname(__FILE__) . '/wp-load.php' ); 
    1414// Redirect to https login if forced to use SSL
    1515if ( force_ssl_admin() && !is_ssl() ) {
    1616        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']));
    1818                exit();
    1919        } 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']);
    2121                exit();
    2222        }
    2323}
    default: 
    518518                $redirect_to = $_REQUEST['redirect_to'];
    519519                // Redirect to https if user wants ssl
    520520                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);
    522522        } else {
    523523                $redirect_to = admin_url();
    524524        }