From 8aab47c60ba9bf99fa48bd06031003bcf0160a91 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Wed, 7 Aug 2024 19:43:11 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/branches/6.6@58862 git-svn-id: http://core.svn.wordpress.org/branches/6.6@58258 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 10 +++++++--- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 0a8621d209..f79ce679f6 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -1366,13 +1366,17 @@ function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac * (which is to say, when they share the domain name of the current request). */ if ( is_ssl() && ! str_starts_with( $image_baseurl, 'https' ) ) { - // Since the `Host:` header might contain a port we should - // compare it against the image URL using the same port. + /* + * Since the `Host:` header might contain a port, it should + * be compared against the image URL using the same port. + */ $parsed = parse_url( $image_baseurl ); - $domain = $parsed['host']; + $domain = isset( $parsed['host'] ) ? $parsed['host'] : ''; + if ( isset( $parsed['port'] ) ) { $domain .= ':' . $parsed['port']; } + if ( $_SERVER['HTTP_HOST'] === $domain ) { $image_baseurl = set_url_scheme( $image_baseurl, 'https' ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 037a593df5..e7d9bd91c8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6.2-alpha-58861'; +$wp_version = '6.6.2-alpha-58862'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.