[wp-trac] [WordPress Trac] #61690: wp_calculate_image_srcset triggers warnings when WP_CONTENT_URL is a relative URL
WordPress Trac
noreply at wordpress.org
Thu Jul 18 09:51:31 UTC 2024
#61690: wp_calculate_image_srcset triggers warnings when WP_CONTENT_URL is a
relative URL
--------------------------+------------------------------
Reporter: mattraines | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Upload | Version: 6.6
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Comment (by mattraines):
I have a workaround if anybody else is stung by this:
{{{#!php
<?php
// wp_calculate_image_srcset does not work with relative WP_CONTENT_URL
because it checks for
// URLs not beginning with https:// to determine whether to upgrade the
paths to SSL.
// Add the site URL to the baseurl for uploads but only if called from
wp_calculate_image_size.
// This allows us to continue using relative URLs elsewhere but does have
the two downsides that:
// 1. it is rather slow
// 2. rendered HTML now includes absolute URLs
add_filter('upload_dir', function($upload_dir){
if (in_array('wp_calculate_image_srcset',
array_column(debug_backtrace(), 'function'))) {
if (!str_contains($upload_dir['baseurl'], '://')) {
$upload_dir['baseurl'] =
trailingslashit(get_option('siteurl'))
. ltrim($upload_dir['baseurl'], '/');
}
}
return $upload_dir;
});
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61690#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list