media_sideload_image
media_sideload_image ( $file, $post_id = 0, $desc = null, $return_type = 'html' )
Parameters:- (string) file The URL of the image to download.
- (int) post_id Optional. The post ID the media is to be associated with.
- (string) desc Optional. Description of the image.
- (string) return_type Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
Returns:- (string|int|WP_Error) Populated HTML img tag, attachment ID, or attachment source on success, WP_Error object otherwise.
Defined at:Change Log: - Introduced in WordPress: 2.6.0
- Deprecated in WordPress: —
Description
Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post.