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:

Leave a reply

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