Searching by GUID not reliable
-
Hey,
So, I had been having trouble getting photos to show up using get_cupp_meta. I had worked around it by using get_the_author_meta and doing a lot of twisty manipulations to get the size of photo I wanted, but was difficult, and seemed fragile. So, I looked deeper into the plugin code, particularly the get_cupp_meta function. It wasn’t returning anything, because the get_attachment_image_by_url function was using the guid value to find the id. It was also trying to parse the url using WP_CONTENT_URL, which wasn’t in the downloads path, anyway. Thus, it was failing in multiple ways to return an id.
After a little searching around, I found that there is a function since WordPress 4.0 called attachment_url_to_postid that takes a path and returns an id, using the _wp_attached_file meta_value to match against. I replaced the get_attachment_image_by_url function call in get_cupp_meta with attachment_url_to_postid and my images are showing up just fine, with the proper sizes and all.
I wonder if you might consider making that change in your plugin. As it stands, I’ve had to hack the plugin, and next time there’s an update, I’ll have to merge your new changes with mine, to maintain consistency. I really like the plugin, because it makes it easy for us to set up our user photos the way we want them.
https://www.ads-software.com/plugins/custom-user-profile-photo/
- The topic ‘Searching by GUID not reliable’ is closed to new replies.