Given a Vimeo ID, I can retrieve a thumbnail from the video via Vimeo Simple API. Rather than call the API every time my page loads I want to set the image as the post thumbnail using the save_post
hook (similar to this question).
My problem is that I am not familiar with URL calls in php. I would like to know:
-
the benefits/drawbacks of using a method like curl compared to
WP_Http
. Is one “better” than the other? -
the order in which I should call functions to successfully set the post thumbnail.
Any help would be greatly appreciated.
My favorite way of handling this problem has been to use a little documented function I discovered on another stack post:
media_sideload_image
It works by fetching an image url to the WordPress upload dir and then associating the image to a post’s attachments.
You can try it like so:
Hi @David John Smith:
1.) If you are in WordPress, (almost) always use
WP_Http
; it’s one of the many things I love about working with WordPress. Why call it and not CURL? Well, because it has a nicer syntax and it calls CURL if CURL is available. If not, it chooses from one of 3 other options. So it really is a brilliant piece of kit.2.) To answer the 2nd question I’ll need to know how you want to name the files you are downloading?