Fix PostFactory::is_image
incorrectly using wp_check_filetype
#2730
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.
Related:
Issue
Images with query params are not correctly identified as images.
Solution
The current way to detect an image is to use
wp_attachment_is_image
and use that withwp_check_filetype
to detect if the file has an expected extension.However,
wp_check_filetype
is not meant to be used with an URL but with a path instead. So this check fails currently if the URL has query params for example.The fix is to use
get_attached_file
to get the actual file path instead of the URL matching whatwp_attachment_is_image
is doing.Impact
I don't think there are any performance or BC changes since this is a bug fix IMHO.
Usage Changes
No.
Considerations
Ideally
wp_attachment_is_image
would been used, but seeing there are custom filters in place this is (no longer) a viable solution so mimicking whatwp_attachment_is_image
is doing seems like the best choice at the moment.Testing
I have to see if I can figure it out, this code path seems untested at the moment and setting up a local dev environment requires a little more time then I can invest right now.