Images Being Deleted
-
We’ve noticed an issue for a while where some avatar images have been deleted. Just the underlying file is being deleted, but the media library entry was not. So we’d have images that didn’t actually exist or load, but still with an entry in the media library.
It wasn’t happening super frequently, so it was hard to pinpoint, but I think I’ve finally tracked down the cause (and was able to replicate on a new install of WordPress with a default WP theme and just this plugin active).
From my testing, this happens when a new avatar is selected (or any other time the avatar_delete function is called). I believe the purpose of the avatar_delete function is to delete any extra registered image sizes (if the image is no longer being used as an avatar).
However, if for some reason one of the local avatar array sizes points to the original file url, the original file url is deleted (which leads to the broken media library shell). In get_simple_local_avatar_url, it seems that the default file path is to the full file, which is often replaced by the resized file, but not always.
One way that seemed reproducible was if the original image was the exact same size as one of the gravatar sizes (I tested with a 192px square as an example).
To me, it seems like one easy way to stop this from happening would be to compare the original file path/url to any of the registered sizes before deleting (to make sure the original file is not deleted). Thanks in advance for your help!
You must be logged in to reply to this topic.