Make WordPress Core

Changeset 35446


Ignore:
Timestamp:
10/30/2015 02:01:32 AM (9 years ago)
Author:
johnbillion
Message:

Ensure that the scheme used in the URL returned by get_blogaddress_by_id() always reflects the blog's URL, instead of using http.

Props thomaswm
Fixes #14867

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-blogs.php

    r35170 r35446  
    3939 */
    4040function get_blogaddress_by_id( $blog_id ) {
    41     $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
    42     return ( $bloginfo ) ? esc_url( 'http://' . $bloginfo->domain . $bloginfo->path ) : '';
     41    $bloginfo = get_blog_details( (int) $blog_id );
     42
     43    if ( empty( $bloginfo ) ) {
     44        return '';
     45    }
     46
     47    $scheme = parse_url( $bloginfo->home, PHP_URL_SCHEME );
     48    $scheme = empty( $scheme ) ? 'http' : $scheme;
     49
     50    return esc_url( $scheme . '://' . $bloginfo->domain . $bloginfo->path );
    4351}
    4452
     
    217225
    218226    switch_to_blog( $blog_id );
    219     $details->blogname      = get_option( 'blogname' );
    220     $details->siteurl       = get_option( 'siteurl' );
    221     $details->post_count    = get_option( 'post_count' );
     227    $details->blogname   = get_option( 'blogname' );
     228    $details->siteurl    = get_option( 'siteurl' );
     229    $details->post_count = get_option( 'post_count' );
     230    $details->home       = get_option( 'home' );
    222231    restore_current_blog();
    223232
  • trunk/tests/phpunit/tests/multisite/site.php

    r35246 r35446  
    10001000        $blogaddress = get_blogaddress_by_id( 42 );
    10011001        $this->assertEquals( '', $blogaddress );
     1002    }
     1003
     1004    /**
     1005     * @ticket 14867
     1006     */
     1007    function test_get_blogaddress_by_id_scheme_reflects_blog_scheme() {
     1008        $blog = self::factory()->blog->create();
     1009
     1010        $this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
     1011
     1012        update_blog_option( $blog, 'home', set_url_scheme( get_blog_option( $blog, 'home' ), 'https' ) );
     1013
     1014        $this->assertSame( 'https', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
     1015    }
     1016
     1017    /**
     1018     * @ticket 14867
     1019     */
     1020    function test_get_blogaddress_by_id_scheme_is_unaffected_by_request() {
     1021        $blog = self::factory()->blog->create();
     1022
     1023        $this->assertFalse( is_ssl() );
     1024        $this->assertSame( 'http', parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME ) );
     1025
     1026        $_SERVER['HTTPS'] = 'on';
     1027
     1028        $is_ssl  = is_ssl();
     1029        $address = parse_url( get_blogaddress_by_id( $blog ), PHP_URL_SCHEME );
     1030
     1031        unset( $_SERVER['HTTPS'] );
     1032
     1033        $this->assertTrue( $is_ssl );
     1034        $this->assertSame( 'http', $address );
    10021035    }
    10031036
Note: See TracChangeset for help on using the changeset viewer.