Make WordPress Core

Opened 8 years ago

Closed 4 years ago

#39562 closed defect (bug) (invalid)

Responsive images: Changing upload path for new attachments will cause srcset path bug

Reported by: zairwolf's profile zairwolf Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7
Component: General Keywords: reporter-feedback close
Focuses: Cc:

Description

for old attachments I used define( 'UPLOADS', 'wp-content/uploads_1' );

for new ones I used define( 'UPLOADS', 'wp-content/uploads_2' );

but when I visit old posts, the attachments' srcset path became uploads_2 while not uploads_1. It caused 404.

in wp-includes/media.php -> function wp_make_content_images_responsive() it uses the current upload path setting to generate all srcset, which is not right for old attachments.

Change History (7)

#1 @joemcgill
8 years ago

  • Keywords reporter-feedback added

Hi @zairwolf,

Thanks for the report. I'm interested in what method you're using to change the value of the UPLOADS constant based on the age of attachments. You may need to implement a similar workaround for srcset.

#2 @zairwolf
8 years ago

@joemcgill Thanks for fast reply. Yes you are right. We changed the upload folder to a new volume after the old disc is full.

I turned off responsive images so far based on

http://wordpress.stackexchange.com/questions/211375/how-do-i-disable-responsive-images-in-wp-4-4

However, I think this is not the ideal way to handle it. Hope there will be a compatibility in future with this situation for srcset :)

#3 @joemcgill
8 years ago

Hi @zairwolf,

Do you have some logic that handles this for src when images are dynamically generated on the front end of your site (e.g., for featured images)? I'd like to see a specific example of what you're doing if you don't mind sharing.

#4 @zairwolf
8 years ago

@joemcgill

src isn't generated dynamically. WP reads the attachment's absolute path from database in wp_get_attachment_url(). Even I changed the upload path for future, the old ones are fine. Please tell me if I am wrong.

So far as I checked, for existing imags, only srcset is generated dynamically.

#5 @joemcgill
8 years ago

For images that are contained in post content, the src is not generated dynamically. But in the src is dynamic for image previews in the media library and for images generated dynamically on the front end (e.g., post_thumbnails). In those cases, wp_get_attachment_url() useswp_get_upload_dir() to create the URL path.

#6 @hellofromTonya
4 years ago

  • Keywords close added

Hello @zairwolf,

Did Joe's answer resolve the issue for you?

Marking this ticket as a close candidate. Why? It's been 4 years with no additional discussion or follow-up. But if the problem still exists today for you, please comment in this ticket and provide the following for further investigation:

Do you have some logic that handles this for src when images are dynamically generated on the front end of your site (e.g., for featured images)? I'd like to see a specific example of what you're doing if you don't mind sharing.

#7 @hellofromTonya
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Given the amount of time that has passed without feedback and not able to reproduce, closing this ticket.

@zairwolf if the issue continues to persist for you today, please follow-up. All information shared helps contributors to continue investigating.

Note: See TracTickets for help on using tickets.