The following snippet supports the article on this page titled "Import Remote Images into WordPress and Return Image URL, Image ID, and Image Dimensions". It will import a remote image into the WordPress media library, create all the relevant image sizes, and return the local image link or array of image data.
1
<?php
2
/*
3
Code to demonstrate the beliefmedia_import_image() function
4
Import Remote Images into WordPress and Return Image URL, Image ID, and Image Dimensions
5
http://www.beliefmedia.com/import-remote-images-wordpress
6
http://www.beliefmedia.com/code/wp-snippets/import-remote-image-demo
7
*/
8
9
10
11
12
'url' => '', /* Image URL */
13
'description' => 'Image',
14
'source' => 0
15
), $atts));
16
17
/* Post ID */
18
global $post;
19
20
/* DB Image hash */
21
22
23
24
25
26
} else {
27
28
29
add_post_meta($post->ID, $hash, $temp);
30
31
}
32
33
/* Return image string or array? */
34
35
36
return $result;
37
}
38
The function is for demonstration purposes only and will require modification before it can be applied in any practical way. That said, you can use it to return the image as follows:
The result:
Of course you'll also need our beliefmedia_import_image()
function. The source article provides further detail.