Opened 11 years ago
Closed 10 years ago
#24518 closed defect (bug) (fixed)
wp_delete_attachment() does not delete all the intermediate image sizes on some conditions
Reported by: | JoshuaAbenazer | Owned by: | wonderboymusic |
---|---|---|---|
Milestone: | 4.1 | Priority: | normal |
Severity: | normal | Version: | 3.5.1 |
Component: | Media | Keywords: | has-patch |
Focuses: | Cc: |
Description
Functionality
The wp_delete_attachment()
function relies on the get_intermediate_image_sizes()
function which in turn depends on the global $_wp_additional_image_sizes
to delete the intermediate image sizes. The global $_wp_additional_image_sizes
is filled with additional images sizes through the add_image_size()
function, either through themes or plugins.
Steps to reproduce the bug
Now consider the following scenario. We have installed a plugin or theme that makes use of add_image_size()
to add an intermediate image. Suppose after using the plugin or theme after few days or months we decide to stop using it for some reason. Now what happens is the particular add_image_size()
that was called by the plugin or theme does not exist anymore. Now I delete a particular media image that was uploaded when the particular theme or plugin was activated. The attachment gets deleted but that one particular size remains in the file system since it wasn't recognized by the global $_wp_additional_image_sizes
Solution
Instead of relying on the get_intermediate_image_sizes()
function or global $_wp_additional_image_sizes
we could just loop through sizes available in the _wp_attachment_metadata
postmeta ( wp_get_attachment_metadata()
)
Attachments (3)
Change History (18)
@
11 years ago
Refreshed version of patch with some spacing adjustments to follow WordPress coding standards.
#7
@
11 years ago
Patch still applies cleanly. Tested and working with an image size that's removed before the attachment is deleted. Anything else to consider?
#8
@
11 years ago
As suggested in my comment above and as communicated to johnbillion at WordCamp Europe, the final consideration is that not everything always exists in meta. (The only situation where this may have occurred is in #22985.)
So, I think we should do both methods.
I also think this is puntable.
#9
@
11 years ago
- Keywords needs-patch added; has-patch 3.7-early commit removed
- Milestone changed from 3.7 to 3.8
wp_delete_attachment() patch