Opened 2 years ago
Closed 2 years 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 |
|---|---|---|---|
| Priority: | normal | Milestone: | 6.6.2 |
| Component: | Upload | Version: | 6.6 |
| Severity: | normal | Keywords: | has-patch fixed-major dev-reviewed commit |
| Cc: | Focuses: |
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.
2 years ago
#2
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/61690
#5
@
2 years ago
- Keywords fixed-major added
- Milestone 6.7 → 6.6.2
- Resolution fixed
- Status closed → reopened
Hi there, thanks for the ticket! Reopening for 6.6.2 consideration.
@SergeyBiryukov commented on PR #7064:
2 years ago
#6
Thanks for the PR! Merged in r58773.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I have a workaround if anybody else is stung by this: