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:

1 comment

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


    This is so awesome!

    Thank you!

Leave a reply

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