#20657 closed defect (bug) (fixed)
Custom Header Image Cropping deletes header images
Reported by: | westi | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.4 | Priority: | high |
Severity: | blocker | Version: | 3.4 |
Component: | Customize | Keywords: | has-patch |
Focuses: | Cc: |
Description
Step to reproduce the issue.
- Go to Appearance → Header when using Twenty Eleven
- Upload an image where one of the dimensions matches the suggested dimensions ( Mine was 1000 width x 649 height)
- Enlarge the cropping marker to cover the whole image (Because I don't want to crop it)
- Hit "Crop and Publish" button
- The header image appears in the Custom Header admin page as expected.
- The header image appears on the front-end also as expected BUT…. wait for a few minutes.
- Open an incognito window to check the front-end.
- Header image is missing :( It's missing in the media library also :(
Looking at the file system I see the file uploaded fine - header.jpg
and then it vanishes and I only have header-462x300.jpg
and friends - no cropped-header.jpg and no original.
The cause for this is the code in Custom_Image_Header::step_3()
it doesn't check the return value from wp_crop_image()
and just assumes that the image will be cropped.
Later in the function we delete the original files and so we have no longer got the file that the "cropped" file attachment would have pointed at.
Relates to the changes for #19840
Attachments (12)
Change History (41)
#2
@
13 years ago
- Component changed from General to Appearance
- Keywords has-patch added; needs-patch removed
#3
@
13 years ago
20657.3.patch also handles the case when wp_crop_image()
returns false.
#5
@
13 years ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In [20769]:
#6
@
13 years ago
- Keywords needs-patch added; has-patch removed
- Resolution fixed deleted
- Status changed from closed to reopened
- Add an image to Media Library which doesn't require cropping (1000x288 for Twenty Eleven).
- Go to Appearance → Header, click "Choose from image library".
- Select the image from point 1, click "Set as header", "Crop and Publish".
- Delete the new "Header Image" attachment from Media Library.
- The original attachment is now orphaned (the files are deleted in point 4).
20657.patch (always run through cropping) seems to be the safest way for now.
Or, wp_crop_image()
should always copy the file under a different name, even with no changes.
#7
@
13 years ago
- Keywords has-patch added; needs-patch removed
Or, wp_crop_image() should always copy the file under a different name, even with no changes.
20657.4.patch implements the idea.
#9
in reply to:
↑ 8
@
13 years ago
Replying to ryan:
Hmmm, leaning toward 20657.patch for 3.4.
Or, maybe not. 3.3 did let you skip cropping in more situations. And not touching an image when not necessary is best.
#10
follow-up:
↓ 12
@
13 years ago
After talking with nacin, .4.patch sounds like the direction to go.
A "Skip Crop, Use Image as Is" type button on the crop page was also discussed. If the image is within the flex limits, present another button that allows skipping the crop so you don't have to pointlessly fiddle with size selection. Seems like it would be a small patch and doable for 3.4, if we like it.
#11
follow-up:
↓ 13
@
13 years ago
20657.5.diff or we can create a new attachment only when the image is cropped.
#12
in reply to:
↑ 10
@
13 years ago
Replying to ryan:
A "Skip Crop, Use Image as Is" type button on the crop page was also discussed. If the image is within the flex limits, present another button that allows skipping the crop so you don't have to pointlessly fiddle with size selection. Seems like it would be a small patch and doable for 3.4, if we like it.
+1. Seems like the most logical thing to do.
#13
in reply to:
↑ 11
@
13 years ago
Replying to greuben:
or we can create a new attachment only when the image is cropped.
That is much simpler. Perhaps 20657.4.patch is not necessary then.
20657.6.patch is an attempt at the "Skip Crop, Use Image as Is" button. Includes 20657.5.diff.
#14
follow-up:
↓ 15
@
13 years ago
If the existing attachment is used when the image is not cropped, then _wp_attachment_is_custom_header could get stomped if the attachement is used by more than one theme. Wondering if always creating a new attachment would be best policy here.
#15
in reply to:
↑ 14
@
13 years ago
Replying to ryan:
Wondering if always creating a new attachment would be best policy here.
Done in 20657.7.patch.
#16
@
13 years ago
Seems like 20657.patch is still the safest way after all, see #20667.
Included in 20657.8.patch. The only remaining concern is that the original attachment is not copied if "Skip Crop, Use Image as Is" was chosen, so comment:14 still applies.
#17
@
13 years ago
The only remaining concern is that the original attachment is not copied if "Skip Crop, Use Image as Is" was chosen, so comment:14 still applies.
Solved in 20657.9.patch.
#18
follow-up:
↓ 19
@
13 years ago
Can $dst_file be constructed from $src_file when src_file is a url? Seems we'd need get_attached_file() to create the dst_file path and name and use _load_image_to_edit_path() as the source when doing the copy().
#19
in reply to:
↑ 18
@
13 years ago
Replying to ryan:
Seems we'd need get_attached_file() to create the dst_file path and name and use _load_image_to_edit_path() as the source when doing the copy().
Right, done in 20657.10.patch. Perhaps we should also silence a possible warning from copy()
in case a file is not accessible for some reason (included in the patch). The error message will be displayed in step_3()
.
#20
follow-up:
↓ 21
@
13 years ago
.10.patch is working well so far.
When uploading an image and then using that image as is with no cropping, is _copy_image_file() necessary? Seems it isn't. Always copying does simplify the logic quite a bit, however.
#21
in reply to:
↑ 20
;
follow-up:
↓ 22
@
13 years ago
Replying to ryan:
When uploading an image and then using that image as is with no cropping, is _copy_image_file() necessary?
I guess so. Otherwise _wp_attachment_is_custom_header
could be overwritten by another theme, as you mentioned in comment:14.
#22
in reply to:
↑ 21
;
follow-up:
↓ 23
@
13 years ago
Replying to SergeyBiryukov:
Replying to ryan:
When uploading an image and then using that image as is with no cropping, is _copy_image_file() necessary?
I guess so. Otherwise
_wp_attachment_is_custom_header
could be overwritten by another theme, as you mentioned in comment:14.
Seems like that path (upload new image from custom header page and skip cropping) creates an attachment with the uploaded image, copies the image in that attachment, updates the attachment with the copied image, and then deletes the original image. The original image and the copy are identical all the way through.
Probably not worth worrying with, but I want to make sure I'm understanding all of the different paths through this code.
#23
in reply to:
↑ 22
@
13 years ago
Replying to ryan:
The original image and the copy are identical all the way through.
Ah, I see. I misread the comment. Will reconsider.
#24
@
13 years ago
20657.11.patch only copies the file if an existing image was selected.
#26
@
13 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
20657.minor-typo-fix.patch fixes a PHPDocs typo and removes debug line.
20657.patch removes the part that was an additional suggestion in #20555.
20657.2.patch makes sure that the file was actually cropped before deleting the original.