WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/16/2016 10:48:13 PM (6 years ago)
Author:
johnbillion
Message:

Media: When generating the base URL to be used in the srcset attribute, use an https scheme when the image base URL's host matches that of the current host, and the request is being served over HTTPS. This prevents mixed content warnings caused by http embedded media.

See #34945
Props joemcgill

File:
1 edited

Legend:

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

    r37018 r37022  
    10271027    $upload_dir = wp_get_upload_dir();
    10281028    $image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname;
     1029
     1030    /*
     1031     * If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain
     1032     * (which is to say, when they share the domain name of the current request).
     1033     */
     1034    if ( is_ssl() && 'https' !== substr( $image_baseurl, 0, 5 ) && parse_url( $image_baseurl, PHP_URL_HOST ) === $_SERVER['HTTP_HOST'] ) {
     1035        $image_baseurl = set_url_scheme( $image_baseurl, 'https' );
     1036    }
    10291037
    10301038    /*
Note: See TracChangeset for help on using the changeset viewer.