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

Fix PostFactory::is_image incorrectly using wp_check_filetype #2730

Merged
merged 1 commit into from May 26, 2023

Conversation

stayallive
Copy link
Contributor

@stayallive stayallive commented Apr 25, 2023

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 with wp_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 what wp_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 what wp_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.

The current way to detect an image is to use `wp_attachment_is_image` and use that with `wp_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 what `wp_attachment_is_image` is doing.
@stayallive stayallive marked this pull request as ready for review April 25, 2023 11:30
@gchtr gchtr added 2.0 help wanted Do you know computer? Then lend a hand and have your code live in infamy! needs-unit-test Ready for Review Ready for a contrib to take a look at and review/merge labels May 16, 2023
@coveralls
Copy link

Coverage Status

Coverage: 88.599%. Remained the same when pulling c208e8b on stayallive:patch-1 into 86f9d10 on timber:2.x.

@gchtr gchtr mentioned this pull request May 17, 2023
30 tasks
Copy link
Member

@nlemoine nlemoine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR @stayallive! You're absolutely right.

@nlemoine nlemoine merged commit 3d6bb88 into timber:2.x May 26, 2023
26 checks passed
@stayallive stayallive deleted the patch-1 branch May 26, 2023 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.0 help wanted Do you know computer? Then lend a hand and have your code live in infamy! needs-unit-test Ready for Review Ready for a contrib to take a look at and review/merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants