When you link to an external image, WordPress will reference the external URL. media_handle_upload
is meant to handle uploaded images that are now living on your server. So unless you're telling the server to download the image from the external source and save it on your server, media_handle_upload
won't apply.
It sounds like you're building your own custom importer. I recommend you take a deeper look at the process. A typical upload:
- User selects file from local system
- File uploads through form to $_POST variable
- WordPress takes file out of POSTed form, runs it through
media_handle_upload
, and stores it on the server
If you're referencing an offsite image and attaching it to the post, WordPress won't do steps 2 and 3. You'll need to add your own scripts to grab the remote image and store a copy locally.