I’ve been meaning to put together something to automatically retrieve remote images and attach them …

I’ve been meaning to put together something to automatically retrieve remote images and attach them to a #WordPress post (for automatically generated posts). I figured I’d have to do something with curl to download the image, save it to a temp file, upload it to WP etc. Turns out there’s a function built in!

All I have to do is add a hook to wp_insert_post that calls media_sideload_image() when it finds the pattern I want, and plug the result into the post content.

https://codex.wordpress.org/Function_Reference/media_sideload_image

On Wandering.shop