Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't filter absolute paths in wp_delete_file() #215

Merged

Conversation

jeremyfelt
Copy link
Contributor

The wp_delete_file filter is used in two different ways by WordPress:

  1. When filtering the filename for the removal of thumbnails, extra image sizes, and backup sizes in wp_delete_attachment(), a relative path is expected in return. This relative path is then used to rebuild the absolute path before unlink() fires.
  2. When filtering directly in 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. When wp_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

The `wp_delete_file` filter  is used in two different ways. When
filtering the filename for the removal of thumbnails, extra image
sizes, and backup sizes, a relative path is expected in return. This
relative path is then used to rebuild the absolute path before
`unlink()` fires.

When filtering directly in `wp_delete_file()`, an absolute path is
expected at all times.

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 humanmade#92
See https://core.trac.wordpress.org/ticket/39476
When `wp_delete_file()` is used directly, then we can assume that
the `delete_attachment` hook does not fire and the absolute file
path can be returned untouched.
@joehoyle
Copy link
Member

This looks good to me, any chance of a unit test for this case @jeremyfelt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants