Opened 9 years ago
Closed 9 years ago
#35102 closed defect (bug) (fixed)
Responsive images support for external URLs
Reported by: | polevaultweb | Owned by: | joemcgill |
---|---|---|---|
Milestone: | 4.4.1 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Media | Keywords: | has-patch fixed-major |
Focuses: | Cc: |
Description (last modified by )
Since the introduction of [35821] in #34898, the ability for srcsets to be added to images with external src URLs has been stopped. For example, our plugin https://wordpress.org/plugins/amazon-s3-and-cloudfront/ replaces local URLs with S3 ones in post content, currently srcset will not be added.
Attachments (1)
Change History (14)
#4
@
9 years ago
- Owner set to joemcgill
- Status changed from new to reviewing
Thanks for the report @polevaultweb. Can you give more information about how your plugin replaces the local URLs? If you can point me to some code that I could look at, that would be helpful as well.
WordPress makes use of the attachment ID information found in the class attribute of the image markup to decide which alternate image sizes should be loaded in a srcset
attribute. To avoid loading the wrong images when the ID is incorrect (e.g., if the markup was imported from another WP installation), we check to make sure the image src
matches one of the image sizes listed in the attachment metadata for that ID. See #34898 and a related bug that might be causing issues for you #35045.
#5
@
9 years ago
No problem @joemcgill! WP Offload S3 (https://wordpress.org/plugins/amazon-s3-and-cloudfront/) copies local files to S3 and then replaces local URLs in post_content via the database, and also hooks into wp_get_attachment_url
to swap local for S3 URLs. The code in [35821] generates URLs for images locally based on image sizes so the image src can be searched for, therefore our S3 URLs will never be found and srcset applied.
Let me know if you need anything further.
#6
@
9 years ago
After a brief Slack chat with @polevaultweb it seems like this use case is something that should be handled by the plugin itself, but after r35821, the wp_calculate_image_srcset
filter is no longer reachable because we bail early if the src
doesn't match one of the available sizes in the attachment meta.
@polevaultweb I wonder if a workaround would be to filter wp_get_attachment_metadata
to insert your offloaded files so wp_image_add_srcset_and_sizes()
can find the corresponding image sizes?
#7
@
9 years ago
#8
@
9 years ago
- Status changed from reviewing to accepted
Thanks @polevaultweb. I'm going to keep this ticket open for now and look into ways we might be able to make the filter in wp_calculate_image_srcset
reachable for cases like these.
#9
@
9 years ago
See https://core.trac.wordpress.org/ticket/35045#comment:18
This is quite close to #35045 and the solution for one of them should fix the other.
The patch adds a filter so the check to see if the image can have srcset added to it can be overridden.