Make WordPress Core


Ignore:
Timestamp:
08/07/2024 07:41:14 PM (2 years ago)
Author:
hellofromTonya
Message:

Media: Check if content URL includes a hostname in wp_calculate_image_srcset().

This resolves an Undefined array key "host" PHP warning if WP_CONTENT_URL is set to a relative URL.

Follow-up to [58097].

Reviewed by hellofromTonya.
Merges [58773] to the 6.6 branch.

Props mattraines, narenin, pamprn, SergeyBiryukov.
Fixes #61690.

Location:
branches/6.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.6

  • branches/6.6/src/wp-includes/media.php

    r58168 r58862  
    13671367         */
    13681368        if ( is_ssl() && ! str_starts_with( $image_baseurl, 'https' ) ) {
    1369                 // Since the `Host:` header might contain a port we should
    1370                 // compare it against the image URL using the same port.
     1369                /*
     1370                 * Since the `Host:` header might contain a port, it should
     1371                 * be compared against the image URL using the same port.
     1372                 */
    13711373                $parsed = parse_url( $image_baseurl );
    1372                 $domain = $parsed['host'];
     1374                $domain = isset( $parsed['host'] ) ? $parsed['host'] : '';
     1375
    13731376                if ( isset( $parsed['port'] ) ) {
    13741377                        $domain .= ':' . $parsed['port'];
    13751378                }
     1379
    13761380                if ( $_SERVER['HTTP_HOST'] === $domain ) {
    13771381                        $image_baseurl = set_url_scheme( $image_baseurl, 'https' );
Note: See TracChangeset for help on using the changeset viewer.