WordPress.org

Make WordPress Core

Changeset 50156


Ignore:
Timestamp:
02/02/2021 07:01:18 PM (2 months ago)
Author:
SergeyBiryukov
Message:

General: Remove admin and login exceptions for https in get_home_url().

Previously, get_home_url() would automatically switch to https if the current request is already https, but would only do so on the front end.

This addresses the inconsistent behavior of returning different values in the admin and on the frontend.

Follow-up to [12598], [21937], [24844].

Props herregroen, mukesh27.
Fixes #52421.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r50132 r50156  
    32543254 * @since 3.0.0
    32553255 *
    3256  * @global string $pagenow
    3257  *
    32583256 * @param int         $blog_id Optional. Site ID. Default null (current site).
    32593257 * @param string      $path    Optional. Path relative to the home URL. Default empty.
     
    32633261 */
    32643262function get_home_url( $blog_id = null, $path = '', $scheme = null ) {
    3265     global $pagenow;
    3266 
    32673263    $orig_scheme = $scheme;
    32683264
     
    32763272
    32773273    if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
    3278         if ( is_ssl() && ! is_admin() && 'wp-login.php' !== $pagenow ) {
     3274        if ( is_ssl() ) {
    32793275            $scheme = 'https';
    32803276        } else {
  • trunk/tests/phpunit/tests/rest-api.php

    r50005 r50156  
    790790        $_SERVER['HTTPS'] = 'on';
    791791        $url              = get_rest_url();
    792         $this->assertSame( 'http', parse_url( $url, PHP_URL_SCHEME ) );
     792        $this->assertSame( 'https', parse_url( $url, PHP_URL_SCHEME ) );
    793793
    794794        // Reset.
  • trunk/tests/phpunit/tests/url.php

    r48937 r50156  
    204204        // Pretend to be in the site admin.
    205205        set_current_screen( 'dashboard' );
    206         $home = get_option( 'home' );
    207 
    208         // home_url() should return http when in the admin.
    209         $_SERVER['HTTPS'] = 'on';
    210         $this->assertSame( $home, home_url() );
     206        $home       = get_option( 'home' );
     207        $home_https = str_replace( 'http://', 'https://', $home );
     208
     209        // is_ssl() should determine the scheme in the admin.
     210        $_SERVER['HTTPS'] = 'on';
     211        $this->assertSame( $home_https, home_url() );
    211212
    212213        $_SERVER['HTTPS'] = 'off';
    213214        $this->assertSame( $home, home_url() );
    214215
    215         // If not in the admin, is_ssl() should determine the scheme.
     216        // is_ssl() should determine the scheme on front end too.
    216217        set_current_screen( 'front' );
    217218        $this->assertSame( $home, home_url() );
    218         $_SERVER['HTTPS'] = 'on';
    219         $home             = str_replace( 'http://', 'https://', $home );
    220         $this->assertSame( $home, home_url() );
     219
     220        $_SERVER['HTTPS'] = 'on';
     221        $this->assertSame( $home_https, home_url() );
    221222
    222223        // Test with https in home.
     
    252253        // Pretend to be in the site admin.
    253254        set_current_screen( 'dashboard' );
    254         $home = network_home_url();
    255 
    256         // home_url() should return http when in the admin.
     255        $home       = network_home_url();
     256        $home_https = str_replace( 'http://', 'https://', $home );
     257
     258        // is_ssl() should determine the scheme in the admin.
    257259        $this->assertSame( 0, strpos( $home, 'http://' ) );
    258260        $_SERVER['HTTPS'] = 'on';
    259         $this->assertSame( $home, network_home_url() );
     261        $this->assertSame( $home_https, network_home_url() );
    260262
    261263        $_SERVER['HTTPS'] = 'off';
    262264        $this->assertSame( $home, network_home_url() );
    263265
    264         // If not in the admin, is_ssl() should determine the scheme.
     266        // is_ssl() should determine the scheme on front end too.
    265267        set_current_screen( 'front' );
    266268        $this->assertSame( $home, network_home_url() );
    267269        $_SERVER['HTTPS'] = 'on';
    268         $home             = str_replace( 'http://', 'https://', $home );
    269         $this->assertSame( $home, network_home_url() );
     270        $this->assertSame( $home_https, network_home_url() );
    270271
    271272        $GLOBALS['current_screen'] = $screen;
Note: See TracChangeset for help on using the changeset viewer.