Video Thumbnails - Version 2.7.9

Version Description

  • Better compatibility with image plugins
  • Better Rutube support
  • Fixed bug that prevented API retrieval error messages
Download this release

Release Info

Developer sutherlandboswell
Plugin Icon 128x128 Video Thumbnails
Version 2.7.9
Comparing to
See all releases

Code changes from version 2.7.8 to 2.7.9

php/extensions/automatic-youtube-video-posts.php CHANGED
@@ -41,18 +41,20 @@ function is_ayvp_importing() {
41
  }
42
 
43
  function ayvp_new_video_thumbnail_url_filter( $new_thumbnail, $post_id ) {
 
 
44
  // When publishing a post during import, use the global variable to generate thumbnail
45
  if ( $new_thumbnail == null && is_ayvp_importing() ) {
46
  global $tern_wp_youtube_array;
47
  if ( isset( $tern_wp_youtube_array['_tern_wp_youtube_video'] ) && $tern_wp_youtube_array['_tern_wp_youtube_video'] != '' ) {
48
- $new_thumbnail = YouTube_Thumbnails::get_thumbnail_url( $tern_wp_youtube_array['_tern_wp_youtube_video'] );
49
  }
50
  }
51
  // When automatic publishing is disabled or rescanning an existing post, use custom field data to generate thumbnail
52
  if ( $new_thumbnail == null ) {
53
  $youtube_id = get_post_meta( $post_id, '_tern_wp_youtube_video', true );
54
  if ( $youtube_id != '' ) {
55
- $new_thumbnail = YouTube_Thumbnails::get_thumbnail_url( $youtube_id );
56
  }
57
  }
58
  return $new_thumbnail;
41
  }
42
 
43
  function ayvp_new_video_thumbnail_url_filter( $new_thumbnail, $post_id ) {
44
+ global $video_thumbnails;
45
+ if ( !isset( $video_thumbnails->providers['youtube'] ) ) return false;
46
  // When publishing a post during import, use the global variable to generate thumbnail
47
  if ( $new_thumbnail == null && is_ayvp_importing() ) {
48
  global $tern_wp_youtube_array;
49
  if ( isset( $tern_wp_youtube_array['_tern_wp_youtube_video'] ) && $tern_wp_youtube_array['_tern_wp_youtube_video'] != '' ) {
50
+ $new_thumbnail = $video_thumbnails->providers['youtube']->get_thumbnail_url( $tern_wp_youtube_array['_tern_wp_youtube_video'] );
51
  }
52
  }
53
  // When automatic publishing is disabled or rescanning an existing post, use custom field data to generate thumbnail
54
  if ( $new_thumbnail == null ) {
55
  $youtube_id = get_post_meta( $post_id, '_tern_wp_youtube_video', true );
56
  if ( $youtube_id != '' ) {
57
+ $new_thumbnail = $video_thumbnails->providers['youtube']->get_thumbnail_url( $youtube_id );
58
  }
59
  }
60
  return $new_thumbnail;
php/providers/class-blip-thumbnails.php CHANGED
@@ -39,7 +39,7 @@ class Blip_Thumbnails extends Video_Thumbnails_Providers {
39
  );
40
 
41
  // Thumbnail URL
42
- public static function get_thumbnail_url( $url ) {
43
  $request = "http://blip.tv/oembed?url=$url";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $url ) {
43
  $request = "http://blip.tv/oembed?url=$url";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
php/providers/class-collegehumor-thumbnails.php CHANGED
@@ -39,7 +39,7 @@ class CollegeHumor_Thumbnails extends Video_Thumbnails_Providers {
39
  );
40
 
41
  // Thumbnail URL
42
- public static function get_thumbnail_url( $id ) {
43
  $request = "http://www.collegehumor.com/oembed.json?url=http%3A%2F%2Fwww.collegehumor.com%2Fvideo%2F$id";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $id ) {
43
  $request = "http://www.collegehumor.com/oembed.json?url=http%3A%2F%2Fwww.collegehumor.com%2Fvideo%2F$id";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
php/providers/class-dailymotion-thumbnails.php CHANGED
@@ -41,7 +41,7 @@ class Dailymotion_Thumbnails extends Video_Thumbnails_Providers {
41
  );
42
 
43
  // Thumbnail URL
44
- public static function get_thumbnail_url( $id ) {
45
  $request = "https://api.dailymotion.com/video/$id?fields=thumbnail_url";
46
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
47
  if( is_wp_error( $response ) ) {
41
  );
42
 
43
  // Thumbnail URL
44
+ public function get_thumbnail_url( $id ) {
45
  $request = "https://api.dailymotion.com/video/$id?fields=thumbnail_url";
46
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
47
  if( is_wp_error( $response ) ) {
php/providers/class-facebook-thumbnails.php CHANGED
@@ -40,7 +40,7 @@ class Facebook_Thumbnails extends Video_Thumbnails_Providers {
40
  );
41
 
42
  // Thumbnail URL
43
- public static function get_thumbnail_url( $id ) {
44
  $request = 'https://graph.facebook.com/' . $id . '/picture?redirect=false';
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
  if( is_wp_error( $response ) ) {
40
  );
41
 
42
  // Thumbnail URL
43
+ public function get_thumbnail_url( $id ) {
44
  $request = 'https://graph.facebook.com/' . $id . '/picture?redirect=false';
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
  if( is_wp_error( $response ) ) {
php/providers/class-funnyordie-thumbnails.php CHANGED
@@ -40,7 +40,7 @@ class Funnyordie_Thumbnails extends Video_Thumbnails_Providers {
40
  );
41
 
42
  // Thumbnail URL
43
- public static function get_thumbnail_url( $id ) {
44
  $request = "http://www.funnyordie.com/oembed.json?url=http%3A%2F%2Fwww.funnyordie.com%2Fvideos%2F$id";
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
  if( is_wp_error( $response ) ) {
40
  );
41
 
42
  // Thumbnail URL
43
+ public function get_thumbnail_url( $id ) {
44
  $request = "http://www.funnyordie.com/oembed.json?url=http%3A%2F%2Fwww.funnyordie.com%2Fvideos%2F$id";
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
  if( is_wp_error( $response ) ) {
php/providers/class-justintv-thumbnails.php CHANGED
@@ -39,7 +39,7 @@ class Justintv_Thumbnails extends Video_Thumbnails_Providers {
39
  );
40
 
41
  // Thumbnail URL
42
- public static function get_thumbnail_url( $id ) {
43
  $request = "http://api.justin.tv/api/clip/show/$id.xml";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $id ) {
43
  $request = "http://api.justin.tv/api/clip/show/$id.xml";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
php/providers/class-kaltura-thumbnails.php CHANGED
@@ -39,7 +39,7 @@ class Kaltura_Thumbnails extends Video_Thumbnails_Providers {
39
  );
40
 
41
  // Thumbnail URL
42
- public static function get_thumbnail_url( $id ) {
43
  $request = "http://www.kaltura.com/api_v3/?service=thumbAsset&action=getbyentryid&entryId=$id";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $id ) {
43
  $request = "http://www.kaltura.com/api_v3/?service=thumbAsset&action=getbyentryid&entryId=$id";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
php/providers/class-metacafe-thumbnails.php CHANGED
@@ -39,7 +39,7 @@ class Metacafe_Thumbnails extends Video_Thumbnails_Providers {
39
  );
40
 
41
  // Thumbnail URL
42
- public static function get_thumbnail_url( $id ) {
43
  $request = "http://www.metacafe.com/api/item/$id/";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $id ) {
43
  $request = "http://www.metacafe.com/api/item/$id/";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
php/providers/class-mpora-thumbnails.php CHANGED
@@ -40,7 +40,7 @@ class Mpora_Thumbnails extends Video_Thumbnails_Providers {
40
  );
41
 
42
  // Thumbnail URL
43
- public static function get_thumbnail_url( $id ) {
44
  return 'http://ugc4.mporatrons.com/thumbs/' . $id . '_640x360_0000.jpg';
45
  }
46
 
40
  );
41
 
42
  // Thumbnail URL
43
+ public function get_thumbnail_url( $id ) {
44
  return 'http://ugc4.mporatrons.com/thumbs/' . $id . '_640x360_0000.jpg';
45
  }
46
 
php/providers/class-rutube-thumbnails.php CHANGED
@@ -35,13 +35,16 @@ class Rutube_Thumbnails extends Video_Thumbnails_Providers {
35
 
36
  // Regex strings
37
  public $regexes = array(
38
- '#(?:https?://)?(?:www\.)?rutube\.ru/video/([A-Za-z0-9]+)#', // Video link
39
- '#(?:https?:)?//rutube\.ru/video/embed/([0-9]+)#', // Embed src
40
  );
41
 
42
  // Thumbnail URL
43
- public static function get_thumbnail_url( $id ) {
44
- $request = "http://rutube.ru/api/video/$id/?format=json";
 
 
 
 
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
  if( is_wp_error( $response ) ) {
47
  $result = $this->construct_info_retrieval_error( $request, $response );
35
 
36
  // Regex strings
37
  public $regexes = array(
38
+ '#(?:https?://)?(?:www\.)?rutube\.ru/video/(?:embed/)?([A-Za-z0-9]+)#', // Video link/Embed src
 
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $id ) {
43
+ if ( strlen( $id ) < 32 ) {
44
+ $request = "http://rutube.ru/api/oembed/?url=http%3A//rutube.ru/tracks/$id.html&format=json";
45
+ } else {
46
+ $request = "http://rutube.ru/api/video/$id/?format=json";
47
+ }
48
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
49
  if( is_wp_error( $response ) ) {
50
  $result = $this->construct_info_retrieval_error( $request, $response );
php/providers/class-twitch-thumbnails.php CHANGED
@@ -40,7 +40,7 @@ class Twitch_Thumbnails extends Video_Thumbnails_Providers {
40
  );
41
 
42
  // Thumbnail URL
43
- public static function get_thumbnail_url( $id ) {
44
  $request = "https://api.twitch.tv/kraken/videos/c$id";
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
  if( is_wp_error( $response ) ) {
40
  );
41
 
42
  // Thumbnail URL
43
+ public function get_thumbnail_url( $id ) {
44
  $request = "https://api.twitch.tv/kraken/videos/c$id";
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
  if( is_wp_error( $response ) ) {
php/providers/class-vimeo-thumbnails.php CHANGED
@@ -71,7 +71,7 @@ class Vimeo_Thumbnails extends Video_Thumbnails_Providers {
71
  );
72
 
73
  // Thumbnail URL
74
- public static function get_thumbnail_url( $id ) {
75
  // Get our settings
76
  $client_id = ( isset( $this ) && isset( $this->options['client_id'] ) && $this->options['client_id'] != '' ? $this->options['client_id'] : false );
77
  $client_secret = ( isset( $this ) && isset( $this->options['client_secret'] ) && $this->options['client_secret'] != '' ? $this->options['client_secret'] : false );
71
  );
72
 
73
  // Thumbnail URL
74
+ public function get_thumbnail_url( $id ) {
75
  // Get our settings
76
  $client_id = ( isset( $this ) && isset( $this->options['client_id'] ) && $this->options['client_id'] != '' ? $this->options['client_id'] : false );
77
  $client_secret = ( isset( $this ) && isset( $this->options['client_secret'] ) && $this->options['client_secret'] != '' ? $this->options['client_secret'] : false );
php/providers/class-vine-thumbnails.php CHANGED
@@ -39,7 +39,7 @@ class Vine_Thumbnails extends Video_Thumbnails_Providers {
39
  );
40
 
41
  // Thumbnail URL
42
- public static function get_thumbnail_url( $id ) {
43
  $request = "https://vine.co/v/$id";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $id ) {
43
  $request = "https://vine.co/v/$id";
44
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
45
  if( is_wp_error( $response ) ) {
php/providers/class-vk-thumbnails.php CHANGED
@@ -39,10 +39,11 @@ class VK_Thumbnails extends Video_Thumbnails_Providers {
39
  );
40
 
41
  // Thumbnail URL
42
- public static function get_thumbnail_url( $id ) {
43
  $request = "http:$id";
44
  $request = html_entity_decode( $request );
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
 
46
  if( is_wp_error( $response ) ) {
47
  $result = $this->construct_info_retrieval_error( $request, $response );
48
  } else {
@@ -64,9 +65,9 @@ class VK_Thumbnails extends Video_Thumbnails_Providers {
64
  public static function get_test_cases() {
65
  return array(
66
  array(
67
- 'markup' => '<iframe src="http://vk.com/video_ext.php?oid=157000410&id=164108685&hash=d9a2915c4d4c2bb4&hd=3" width="607" height="360" frameborder="0"></iframe>',
68
- 'expected' => 'http://cs518315.vk.me/u157000410/video/l_5ed29d68.jpg',
69
- 'expected_hash' => '2d603fbec41701cf6db9b5402c1e90f0',
70
  'name' => __( 'iFrame Embed', 'video-thumbnails' )
71
  ),
72
  );
39
  );
40
 
41
  // Thumbnail URL
42
+ public function get_thumbnail_url( $id ) {
43
  $request = "http:$id";
44
  $request = html_entity_decode( $request );
45
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
46
+ $result = false;
47
  if( is_wp_error( $response ) ) {
48
  $result = $this->construct_info_retrieval_error( $request, $response );
49
  } else {
65
  public static function get_test_cases() {
66
  return array(
67
  array(
68
+ 'markup' => '<iframe src="http://vk.com/video_ext.php?oid=220943440&id=168591360&hash=75a37bd3930f4fab&hd=1" width="607" height="360" frameborder="0"></iframe>',
69
+ 'expected' => 'http://cs540302.vk.me/u220943440/video/l_afc9770f.jpg',
70
+ 'expected_hash' => 'fd8c2af4ad5cd4e55afe129d80b42d8b',
71
  'name' => __( 'iFrame Embed', 'video-thumbnails' )
72
  ),
73
  );
php/providers/class-wistia-thumbnails.php CHANGED
@@ -52,7 +52,7 @@ class Wistia_Thumbnails extends Video_Thumbnails_Providers {
52
  );
53
 
54
  // Thumbnail URL
55
- public static function get_thumbnail_url( $id ) {
56
 
57
  // ID is an image URL, return it
58
  if ( substr( $id, -4 ) == '.jpg' ) return $id;
52
  );
53
 
54
  // Thumbnail URL
55
+ public function get_thumbnail_url( $id ) {
56
 
57
  // ID is an image URL, return it
58
  if ( substr( $id, -4 ) == '.jpg' ) return $id;
php/providers/class-youku-thumbnails.php CHANGED
@@ -41,7 +41,7 @@ class Youku_Thumbnails extends Video_Thumbnails_Providers {
41
  );
42
 
43
  // Thumbnail URL
44
- public static function get_thumbnail_url( $id ) {
45
  $request = "http://v.youku.com/player/getPlayList/VideoIDS/$id/";
46
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
47
  if( is_wp_error( $response ) ) {
41
  );
42
 
43
  // Thumbnail URL
44
+ public function get_thumbnail_url( $id ) {
45
  $request = "http://v.youku.com/player/getPlayList/VideoIDS/$id/";
46
  $response = wp_remote_get( $request, array( 'sslverify' => false ) );
47
  if( is_wp_error( $response ) ) {
php/providers/class-youtube-thumbnails.php CHANGED
@@ -43,7 +43,7 @@ class YouTube_Thumbnails extends Video_Thumbnails_Providers {
43
  );
44
 
45
  // Thumbnail URL
46
- public static function get_thumbnail_url( $id ) {
47
  $maxres = 'http://img.youtube.com/vi/' . $id . '/maxresdefault.jpg';
48
  $response = wp_remote_head( $maxres );
49
  if ( !is_wp_error( $response ) && $response['response']['code'] == '200' ) {
43
  );
44
 
45
  // Thumbnail URL
46
+ public function get_thumbnail_url( $id ) {
47
  $maxres = 'http://img.youtube.com/vi/' . $id . '/maxresdefault.jpg';
48
  $response = wp_remote_head( $maxres );
49
  if ( !is_wp_error( $response ) && $response['response']['code'] == '200' ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://wie.ly/u/donate
4
  Tags: Video, Thumbnails, YouTube, Vimeo, Vine, Twitch, Dailymotion, Youku, Rutube, Featured Image
5
  Requires at least: 3.2
6
  Tested up to: 3.9
7
- Stable tag: 2.7.8
8
 
9
  Video Thumbnails simplifies the process of automatically displaying video thumbnails in your WordPress template.
10
 
@@ -83,7 +83,7 @@ No, Video Thumbnails only uses thumbnails provided by the source. If you're post
83
 
84
  = Can it get thumbnails for my self-hosted videos? =
85
 
86
- No, it will only fetch thumbnails for videos from the list of supported sites. Decoding local video files to create thumbnails would require server resources and packages unavailable to most users, so the plugin focuses on .
87
 
88
  = My theme isn't showing thumbnails, what's wrong? =
89
 
@@ -130,6 +130,11 @@ The Vimeo API has a rate limit, so in rare cases you may exceed this limit. Try
130
 
131
  == Changelog ==
132
 
 
 
 
 
 
133
  = 2.7.8 =
134
  * Improved Facebook detection
135
  * Higher resolution Facebook thumbnails (when available)
4
  Tags: Video, Thumbnails, YouTube, Vimeo, Vine, Twitch, Dailymotion, Youku, Rutube, Featured Image
5
  Requires at least: 3.2
6
  Tested up to: 3.9
7
+ Stable tag: 2.7.9
8
 
9
  Video Thumbnails simplifies the process of automatically displaying video thumbnails in your WordPress template.
10
 
83
 
84
  = Can it get thumbnails for my self-hosted videos? =
85
 
86
+ No, it will only fetch thumbnails for videos from the list of supported sites. Decoding local video files to create thumbnails would require server resources and packages unavailable to most users, so we only focus on supporting major video sites.
87
 
88
  = My theme isn't showing thumbnails, what's wrong? =
89
 
130
 
131
  == Changelog ==
132
 
133
+ = 2.7.9 =
134
+ * Better compatibility with image plugins
135
+ * Better Rutube support
136
+ * Fixed bug that prevented API retrieval error messages
137
+
138
  = 2.7.8 =
139
  * Improved Facebook detection
140
  * Higher resolution Facebook thumbnails (when available)
video-thumbnails.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: https://refactored.co/plugins/video-thumbnails
5
  Description: Automatically retrieve video thumbnails for your posts and display them in your theme. Supports YouTube, Vimeo, Facebook, Vine, Justin.tv, Twitch, Dailymotion, Metacafe, VK, Blip, Google Drive, Funny or Die, CollegeHumor, MPORA, Wistia, Youku, and Rutube.
6
  Author: Sutherland Boswell
7
  Author URI: http://sutherlandboswell.com
8
- Version: 2.7.8
9
  License: GPL2
10
  Text Domain: video-thumbnails
11
  Domain Path: /languages/
@@ -30,7 +30,7 @@ Domain Path: /languages/
30
 
31
  define( 'VIDEO_THUMBNAILS_PATH', dirname(__FILE__) );
32
  define( 'VIDEO_THUMBNAILS_FIELD', '_video_thumbnail' );
33
- define( 'VIDEO_THUMBNAILS_VERSION', '2.7.8' );
34
 
35
  // Providers
36
  require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-providers.php' );
@@ -383,22 +383,28 @@ class Video_Thumbnails {
383
 
384
  do_action( 'video_thumbnails/image_downloaded', $upload['file'] );
385
 
386
- $image_url = $upload['url'];
387
 
388
- $filename = $upload['file'];
 
 
 
 
389
 
390
- $wp_filetype = wp_check_filetype( basename( $filename ), null );
391
  $attachment = array(
392
- 'post_mime_type' => $wp_filetype['type'],
393
  'post_title' => get_the_title( $post_id ),
394
  'post_content' => '',
395
  'post_status' => 'inherit'
396
  );
397
- $attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
 
 
398
  // you must first include the image.php file
399
  // for the function wp_generate_attachment_metadata() to work
400
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
401
- $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
402
  wp_update_attachment_metadata( $attach_id, $attach_data );
403
 
404
  // Add field to mark image as a video thumbnail
5
  Description: Automatically retrieve video thumbnails for your posts and display them in your theme. Supports YouTube, Vimeo, Facebook, Vine, Justin.tv, Twitch, Dailymotion, Metacafe, VK, Blip, Google Drive, Funny or Die, CollegeHumor, MPORA, Wistia, Youku, and Rutube.
6
  Author: Sutherland Boswell
7
  Author URI: http://sutherlandboswell.com
8
+ Version: 2.7.9
9
  License: GPL2
10
  Text Domain: video-thumbnails
11
  Domain Path: /languages/
30
 
31
  define( 'VIDEO_THUMBNAILS_PATH', dirname(__FILE__) );
32
  define( 'VIDEO_THUMBNAILS_FIELD', '_video_thumbnail' );
33
+ define( 'VIDEO_THUMBNAILS_VERSION', '2.7.9' );
34
 
35
  // Providers
36
  require_once( VIDEO_THUMBNAILS_PATH . '/php/providers/class-video-thumbnails-providers.php' );
383
 
384
  do_action( 'video_thumbnails/image_downloaded', $upload['file'] );
385
 
386
+ $wp_filetype = wp_check_filetype( basename( $upload['file'] ), null );
387
 
388
+ $upload = apply_filters( 'wp_handle_upload', array(
389
+ 'file' => $upload['file'],
390
+ 'url' => $upload['url'],
391
+ 'type' => $wp_filetype['type']
392
+ ), 'sideload' );
393
 
394
+ // Contstruct the attachment array
395
  $attachment = array(
396
+ 'post_mime_type' => $upload['type'],
397
  'post_title' => get_the_title( $post_id ),
398
  'post_content' => '',
399
  'post_status' => 'inherit'
400
  );
401
+ // Insert the attachment
402
+ $attach_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
403
+
404
  // you must first include the image.php file
405
  // for the function wp_generate_attachment_metadata() to work
406
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
407
+ $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] );
408
  wp_update_attachment_metadata( $attach_id, $attach_data );
409
 
410
  // Add field to mark image as a video thumbnail