Opened 5 months ago
Closed 4 months ago
#61690 closed defect (bug) (fixed)
wp_calculate_image_srcset triggers warnings when WP_CONTENT_URL is a relative URL
Reported by: | mattraines | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.6.2 | Priority: | normal |
Severity: | normal | Version: | 6.6 |
Component: | Upload | Keywords: | has-patch fixed-major dev-reviewed commit |
Focuses: | Cc: |
Description
I'm aware that this is unsupported and WP_CONTENT_URL should be an absolute URL including protocol and hostname, but we like to use a path starting with / as it makes our data more portable for testing and development.
The warning is triggered by
<?php $domain = $parsed['host'];
PHP Warning: Undefined array key "host" in .../wp-includes/media.php on line 1372
The warnings are new in 6.6.0.
Suggested fix:
Either
<?php if ( is_ssl() && str_contains(':') && ! 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. $parsed = parse_url( $image_baseurl ); $domain = $parsed['host']; if ( isset( $parsed['port'] ) ) { $domain .= ':' . $parsed['port']; } if ( $_SERVER['HTTP_HOST'] === $domain ) { $image_baseurl = set_url_scheme( $image_baseurl, 'https' ); } }
or
<?php 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. if ( $parsed = parse_url( $image_baseurl ) ) { $domain = $parsed['host']; if ( isset( $parsed['port'] ) ) { $domain .= ':' . $parsed['port']; } if ( $_SERVER['HTTP_HOST'] === $domain ) { $image_baseurl = set_url_scheme( $image_baseurl, 'https' ); } } }
Change History (8)
This ticket was mentioned in PR #7064 on WordPress/wordpress-develop by @narenin.
5 months ago
#2
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/61690
#3
@
5 months ago
- Milestone changed from Awaiting Review to 6.7
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
#5
@
5 months ago
- Keywords fixed-major added
- Milestone changed from 6.7 to 6.6.2
- Resolution fixed deleted
- Status changed from closed to reopened
Hi there, thanks for the ticket! Reopening for 6.6.2 consideration.
@SergeyBiryukov commented on PR #7064:
5 months ago
#6
Thanks for the PR! Merged in r58773.
Note: See
TracTickets for help on using
tickets.
I have a workaround if anybody else is stung by this: