I built the following class that downloads a remote image, moves it into the /uploads/ directory of your site, adds it to WordPress as a new attachment and returns to you the attachment ID. Example usage is shown further down the page.

Example Usage

Below are two examples of how you can use this class to download a remote image and set it as the featured image for a WordPress post.

The image that was downloaded in example 2 looks like this in the Media Library:

3 comments

  1. Max October 25, 2018 at 4:32 am

    Reply

    Hello,
    Your remote image downloader function is awesome. I try it on my blog and its working very well.
    I have a image filter function (ie. image_filter(‘resize’,400); ) and i wanna use it along with your function. Where should i put those line in your function?
    Thank you!

    • Kellen Mace November 22, 2018 at 9:32 pm

      Reply

      Hi Max! Glad it’s coming in handy. I’m not sure what your image_filer() function does, so I can’t quite answer that question. You may want to have a look at using add_image_size(). That would allow you to define a new image size and every image inserted into the media library would then be cropped to that size, so it would be available for use. Best of luck!

  2. Felipe November 9, 2018 at 1:16 pm

    Reply

    This is so awesome!

    Thank you!

Leave a reply

Your email address will not be published. Required fields are marked *