Closed mlq closed 7 years ago
Hey @mlq
Thank you very much for the pull request!
Until now I always checked in the theme code whether the ID of the image is actually an attachment. But I guess it would make sense to have Timmy check this and return an empty string when it’s not attachment or the image could not be found. For performance it would be best to check for this as early as possible.
Your patch hooks into the image_downsize
filter, which is called when additional image sizes for an image are generated. Because this filter is not called every time an image is requested, I can still see the error message. Now, I think it would help if you could tell me which function or Twig filter you uses to display the image/get the image source.
I will look into this further and will try to catch all cases where that notice might appear.
This should now be fixed by https://github.com/MINDKomm/timmy/commit/e81e5011e233bd2641345f543959e9e6f0e96454.
Timmy now returns false
when an image can’t be found. This means that you won’t see any error messages for missing images.
After upgrading wordpress to 4.7 and Timber to 1.1.12 I've experienced a 'Trying to get property of non-object' error message in the filter_image_downsize function as an attachment for the passed attachment id does not exist.
This patch checks if the attachment returned by get_post is no non-object and bails out of this function accordingly.