Don't filter absolute paths in wp_delete_file() #215
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
wp_delete_file
filter is used in two different ways by WordPress:wp_delete_attachment()
, a relative path is expected in return. This relative path is then used to rebuild the absolute path beforeunlink()
fires.wp_delete_file()
, an absolute path is expected at all times.We can identify when each of these is used by capturing the original file's absolute path when
delete_attachment
fires and only leaving that untouched. Whenwp_delete_file()
is used directly, no original file is captured, so the path is left untouched.This fixes a case where original files would not be deleted from S3 when removed from the media library, but where all of the thumbnails would be deleted.
See #92
See https://core.trac.wordpress.org/ticket/39476