media_sideload_image
could be a super useful function, except for one thing, it returns image HTML which is limited in what it can be used for.
What if it returned the attachment ID? That would be useful and media_sideload_image
comes so close!
I've needed this a few times in the past and I've just had to copy/paste this function and edit it to return ID. Some examples of when I could have used this:
- writing content importers
- a plugin to sideload external images from post content comments on save
My proposal is to split media_sideload_image
into 2 functions. The first, media_handle_sideload_image
sideloads the image and returns the attachment ID. The second media_sideload_image
returns the image HTML.