Video Thumbnails - Version 1.0

Version Description

  • Video Thumbnails can now be stored in the local WordPress media library
  • Video Thumbnails stored locally can automatically be set as the featured image, making it support many themes automatically
  • Added an options page to enable/disable local storage and enable/disable automatically setting that thumbnail as the featured image
  • Settings page also includes a button to scan all posts for video thumbnails
Download this release

Release Info

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

Code changes from version 0.6 to 1.0

Files changed (3) hide show
  1. default.jpg +0 -0
  2. readme.txt +48 -15
  3. video-thumbnails.php +173 -2
default.jpg CHANGED
Binary file
readme.txt CHANGED
@@ -1,50 +1,75 @@
1
  === Video Thumbnails ===
2
  Contributors: sutherlandboswell
3
- Donate link: http://sutherlandboswell.com/2010/11/wordpress-video-thumbnails/
4
- Tags: Video, YouTube, Vimeo, Blip.tv, Thumbnails
5
  Requires at least: 3.0
6
- Tested up to: 3.0.3
7
- Stable tag: 0.6
8
 
9
  Video Thumbnails is a simple plugin that makes it easy to automatically display video thumbnails in your template.
10
 
11
  == Description ==
12
 
13
- Video Thumbnails makes it simple to display video thumbnails in your templates. Simply use `<?php video_thumbnail(); ?>` in a loop to find and echo the URL of the first video embedded in a post, or use `<?php $video_thumbnail = get_video_thumbnail(); ?>` if you want to return the URL for use as a variable.
14
 
15
- Video Thumbnails currently supports:
16
 
17
  * YouTube
18
  * Vimeo
19
  * Justin.tv
20
  * Blip.tv
 
 
 
21
  * [Simple Video Embedder](http://wordpress.org/extend/plugins/simple-video-embedder/)
22
  * [Vimeo Shortcode](http://blog.esimplestudios.com/2010/08/embedding-vimeo-videos-in-wordpress/)
23
  * [JR Embed](http://plugins.jakeruston.co.uk/wordpress/wordpress-plugin-jr-embed/)
24
 
25
- When using `video_thumbnail()` and no thumbnail is found, a default thumbnail is echoed, which can be changed by replacing the `default.jpg` file found in your `/plugins/video-thumbnails/` directory.
26
 
27
- For more advanced users, the `get_video_thumbnail()` function will return null when no thumbnail is found so a conditional statement can be used to detect if a thumbnail is present and decide what to echo. Here's an example of how to only echo a thumbnail when one is found: `<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='" . $video_thumbnail . "' />"; } ?>`
 
28
 
29
  == Installation ==
30
 
31
  1. Upload the `/video-thumbnails/` directory to the `/wp-content/plugins/` directory
32
  1. Activate the plugin through the 'Plugins' menu in WordPress
33
- 1. Use `<?php video_thumbnail(); ?>` in a loop inside your template to echo the thumbnail URL. Because this is only a URL, you should set it as an image tag's source. For example, `<img src="<?php video_thumbnail(); ?>" />`. If you'd like to return the URL for use in your PHP, use `get_video_thumbnail()`. For example, `<?php $video_thumbnail = get_video_thumbnail(); ?>`.
34
 
35
  == Frequently Asked Questions ==
36
 
 
 
 
 
37
  = Can I use the functions outside of a loop? =
38
 
39
- Yes, but you must pass the post ID to the function as a parameter. For example: `<?php $id = 25; $thumbnail = get_video_thumbnail($id); if($thumbnail!=null) echo $thumbnail; ?>`
40
 
41
  = My video service/embedding plugin isn't included, can you add it? =
42
 
43
  If the service allows a way to retrieve thumbnails, I'll do my best to add it.
44
 
45
- = I only want a thumbnail when one is found, how would I do this? =
 
 
 
 
 
 
 
 
46
 
47
- In version 0.2 `get_video_thumbnail()` was added which returns null when no thumbnail is found. This means you can use something like `<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='" . $video_thumbnail . "' />"; } ?>` to only display a thumbnail when one exists.
 
 
 
 
 
 
 
 
 
 
48
 
49
  == Screenshots ==
50
 
@@ -52,6 +77,12 @@ In version 0.2 `get_video_thumbnail()` was added which returns null when no thum
52
 
53
  == Changelog ==
54
 
 
 
 
 
 
 
55
  = 0.6 =
56
  * Added support for Justin.tv
57
  * Fixed bug that could cause a conflict with other plugins
@@ -105,6 +136,9 @@ In version 0.2 `get_video_thumbnail()` was added which returns null when no thum
105
 
106
  == Upgrade Notice ==
107
 
 
 
 
108
  = 0.5 =
109
  This version adds the thumbnail URL to the post's meta data, meaning any outside APIs only have to be queried once per post. Vimeo's rate limit was easily exceeded, so this should fix that problem.
110
 
@@ -116,8 +150,7 @@ This version adds the thumbnail URL to the post's meta data, meaning any outside
116
 
117
  This plugin is still very young, and has a future planned as the ultimate plugin for video thumbnails. Here's some of the planned additions:
118
 
119
- * An option to save thumbnails as post attachments and as the featured image, giving the plugin out-of-the-box compatibility with themes that use the Featured Image functionality of WordPress (I'd like some feedback on this idea)
120
- * More comprehensive Blip.tv support
121
  * More services
122
- * Broader plugin compatibility
123
  * Option to display video thumbnails on the admin post list page
1
  === Video Thumbnails ===
2
  Contributors: sutherlandboswell
3
+ Donate link: http://amzn.com/w/1L25YG6FO8AZ1
4
+ Tags: Video, YouTube, Vimeo, Blip.tv, Justin.tv, Thumbnails
5
  Requires at least: 3.0
6
+ Tested up to: 3.0.4
7
+ Stable tag: 1.0
8
 
9
  Video Thumbnails is a simple plugin that makes it easy to automatically display video thumbnails in your template.
10
 
11
  == Description ==
12
 
13
+ Video Thumbnails makes it easy to automatically display video thumbnails in your template. This plugin will pull the thumbnail for you, save it to your media library, and set it as the featured image. You can choose to turn off featured images
14
 
15
+ Video Thumbnails currently supports these video services:
16
 
17
  * YouTube
18
  * Vimeo
19
  * Justin.tv
20
  * Blip.tv
21
+
22
+ Support is also included for the following plugins, with universal plugin support coming soon:
23
+
24
  * [Simple Video Embedder](http://wordpress.org/extend/plugins/simple-video-embedder/)
25
  * [Vimeo Shortcode](http://blog.esimplestudios.com/2010/08/embedding-vimeo-videos-in-wordpress/)
26
  * [JR Embed](http://plugins.jakeruston.co.uk/wordpress/wordpress-plugin-jr-embed/)
27
 
28
+ Some functions are available to advanced users who want to customize their theme:
29
 
30
+ * `<?php video_thumbnail(); ?>` will echo a thumbnail URL or the default image located at `wp-content/plugins/video-thumbnails/default.jpg` if a thumbnail cannot be found. Here is an example: `<img src="<?php video_thumbnail(); ?>" width="300" />`
31
+ * `<?php $video_thumbnail = get_video_thumbnail(); ?>` will return the thumbnail URL or return NULL if none is found. In this example, a thumbnail is only shown if one is found: `<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='" . $video_thumbnail . "' />"; } ?>`
32
 
33
  == Installation ==
34
 
35
  1. Upload the `/video-thumbnails/` directory to the `/wp-content/plugins/` directory
36
  1. Activate the plugin through the 'Plugins' menu in WordPress
 
37
 
38
  == Frequently Asked Questions ==
39
 
40
+ = My theme isn't showing thumbnails, what's wrong? =
41
+
42
+ The most likely problem is that your theme doesn't support post thumbnails. If thumbnails are supported, you should see a box titled "Featured Image" on the edit post page. If thumbnails aren't supported, your theme will have to be modified.
43
+
44
  = Can I use the functions outside of a loop? =
45
 
46
+ Yes, but you must pass the post ID to the function as a parameter. For example: `<?php $thumbnail = get_video_thumbnail(25); ?>`
47
 
48
  = My video service/embedding plugin isn't included, can you add it? =
49
 
50
  If the service allows a way to retrieve thumbnails, I'll do my best to add it.
51
 
52
+ = I am editing my theme and only want to display a thumbnail if one is found. How do I do this? =
53
+
54
+ `<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='" . $video_thumbnail . "' />"; } ?>` will only display a thumbnail when one exists.
55
+
56
+ = I edited my theme and now I'm getting huge thumbnails, how can I resize them? =
57
+
58
+ Adding a width attribute to the image element should scale the image in most modern browsers. Ex: `<?php if( ( $video_thumbnail = get_video_thumbnail() ) != null ) { echo "<img src='" . $video_thumbnail . "' width='300' />"; } ?>`
59
+
60
+ You can also assign a class to the element and style it with CSS, or even use a library like [TimThumb](http://code.google.com/p/timthumb/) to resize your images.
61
 
62
+ = I edited my theme and now I'm seeing the thumbnail and the video, how do I only display the thumbnail? =
63
+
64
+ Every theme is different, so this can be tricky if you aren't familiar with WordPress theme development. You need to edit your template in the appropriate place, replacing `<?php the_content(); >` with `<?php the_excerpt(); >` so that only an excerpt of the post is shown on the home page or wherever you would like to display the video thumbnail.
65
+
66
+ = Why are there black bars on some YouTube thumbnails? =
67
+
68
+ This is an unfortunate side effect of widescreen videos on YouTube. The thumbnail YouTube provides is always the same ratio, which creates black bars when a video is widescreen. Some themes will crop featured images and it may not be visible, but if you are comfortable editing your theme, I recommend using [TimThumb](http://code.google.com/p/timthumb/) to resize and crop your images.
69
+
70
+ = Why did it stop finding thumbnails for Vimeo? =
71
+
72
+ The Vimeo API has a rate limit, so in rare cases you may exceed this limit. Try again after a few hours.
73
 
74
  == Screenshots ==
75
 
77
 
78
  == Changelog ==
79
 
80
+ = 1.0 =
81
+ * Video Thumbnails can now be stored in the local WordPress media library
82
+ * Video Thumbnails stored locally can automatically be set as the featured image, making it support many themes automatically
83
+ * Added an options page to enable/disable local storage and enable/disable automatically setting that thumbnail as the featured image
84
+ * Settings page also includes a button to scan all posts for video thumbnails
85
+
86
  = 0.6 =
87
  * Added support for Justin.tv
88
  * Fixed bug that could cause a conflict with other plugins
136
 
137
  == Upgrade Notice ==
138
 
139
+ = 1.0 =
140
+ This is the single biggest update to Video Thumbnails so far, so be sure to check out the new settings page and documentation.
141
+
142
  = 0.5 =
143
  This version adds the thumbnail URL to the post's meta data, meaning any outside APIs only have to be queried once per post. Vimeo's rate limit was easily exceeded, so this should fix that problem.
144
 
150
 
151
  This plugin is still very young, and has a future planned as the ultimate plugin for video thumbnails. Here's some of the planned additions:
152
 
153
+ * Better Blip.tv support
 
154
  * More services
155
+ * Universal plugin compatibility
156
  * Option to display video thumbnails on the admin post list page
video-thumbnails.php CHANGED
@@ -2,10 +2,10 @@
2
  /*
3
  Plugin Name: Video Thumbnails
4
  Plugin URI: http://sutherlandboswell.com/2010/11/wordpress-video-thumbnails/
5
- Description: Make adding video thumbnails to your posts easier and automatic, just add <code>&lt;?php video_thumbnail(); ?&gt;</code> to your loop to get the thumbnail's URL. <code>&lt;?php get_video_thumbnail(); ?&gt;</code> is also available for more advanced users. Currently works with YouTube, Vimeo, Justin.tv, and Blip.tv, along with several embedding plugins.
6
  Author: Sutherland Boswell
7
  Author URI: http://sutherlandboswell.com
8
- Version: 0.6
9
  License: GPL2
10
  */
11
  /* Copyright 2010 Sutherland Boswell (email : sutherland.boswell@gmail.com)
@@ -172,7 +172,41 @@ function get_video_thumbnail($post_id=null) {
172
 
173
  // Return the new thumbnail variable and update meta if one is found
174
  if($new_thumbnail!=null) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  if(!update_post_meta($post_id, '_video_thumbnail', $new_thumbnail)) add_post_meta($post_id, '_video_thumbnail', $new_thumbnail);
 
 
 
 
 
 
 
176
  }
177
  return $new_thumbnail;
178
 
@@ -226,4 +260,141 @@ function save_video_thumbnail($post_ID){
226
  get_video_thumbnail($post_ID);
227
  }
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  ?>
2
  /*
3
  Plugin Name: Video Thumbnails
4
  Plugin URI: http://sutherlandboswell.com/2010/11/wordpress-video-thumbnails/
5
+ Description: Automatically retrieve video thumbnails for your posts and display them in your theme. Currently supports YouTube, Vimeo, Blip.tv, and Justin.tv.
6
  Author: Sutherland Boswell
7
  Author URI: http://sutherlandboswell.com
8
+ Version: 1.0
9
  License: GPL2
10
  */
11
  /* Copyright 2010 Sutherland Boswell (email : sutherland.boswell@gmail.com)
172
 
173
  // Return the new thumbnail variable and update meta if one is found
174
  if($new_thumbnail!=null) {
175
+
176
+ // Save as Attachment if enabled
177
+ if(get_option('video_thumbnails_save_media')==1) {
178
+
179
+ $upload = wp_upload_bits(basename($new_thumbnail), null, file_get_contents($new_thumbnail));
180
+
181
+ $new_thumbnail = $upload['url'];
182
+
183
+ $filename = $upload['file'];
184
+
185
+ $wp_filetype = wp_check_filetype(basename($filename), null );
186
+ $attachment = array(
187
+ 'post_mime_type' => $wp_filetype['type'],
188
+ 'post_title' => get_the_title($post_id),
189
+ 'post_content' => '',
190
+ 'post_status' => 'inherit'
191
+ );
192
+ $attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
193
+ // you must first include the image.php file
194
+ // for the function wp_generate_attachment_metadata() to work
195
+ require_once(ABSPATH . "wp-admin" . '/includes/image.php');
196
+ $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
197
+ wp_update_attachment_metadata( $attach_id, $attach_data );
198
+
199
+ }
200
+
201
+ // Add hidden custom field with thumbnail URL
202
  if(!update_post_meta($post_id, '_video_thumbnail', $new_thumbnail)) add_post_meta($post_id, '_video_thumbnail', $new_thumbnail);
203
+
204
+ // Set attachment as featured image if enabled
205
+ if(get_option('video_thumbnails_set_featured')==1 && get_option('video_thumbnails_save_media')==1) {
206
+ if(!has_post_thumbnail($post_id)) {
207
+ if(!update_post_meta($post_id, '_thumbnail_id', $attach_id)) add_post_meta($post_id, '_thumbnail_id', $attach_id);
208
+ }
209
+ }
210
  }
211
  return $new_thumbnail;
212
 
260
  get_video_thumbnail($post_ID);
261
  }
262
 
263
+ // Set Default Options
264
+
265
+ register_activation_hook(__FILE__,'video_thumbnails_activate');
266
+ register_deactivation_hook(__FILE__,'video_thumbnails_deactivate');
267
+
268
+ function video_thumbnails_activate() {
269
+ add_option('video_thumbnails_save_media','1');
270
+ add_option('video_thumbnails_set_featured','1');
271
+ }
272
+
273
+ function video_thumbnails_deactivate() {
274
+ delete_option('video_thumbnails_save_media');
275
+ delete_option('video_thumbnails_set_featured');
276
+ }
277
+
278
+ // Aministration
279
+
280
+ add_action('admin_menu', 'video_thumbnails_menu');
281
+
282
+ function video_thumbnails_menu() {
283
+
284
+ add_options_page('Video Thumbnail Options', 'Video Thumbnails', 'manage_options', 'video-thumbnail-options', 'video_thumbnail_options');
285
+
286
+ }
287
+
288
+ function video_thumbnail_options() {
289
+
290
+ if (!current_user_can('manage_options')) {
291
+ wp_die( __('You do not have sufficient permissions to access this page.') );
292
+ }
293
+
294
+ function video_thumbnails_checkbox_option($option_name, $option_description) { ?>
295
+ <fieldset><legend class="screen-reader-text"><span><?php echo $option_description; ?></span></legend>
296
+ <label for="<?php echo $option_name; ?>"><input name="<?php echo $option_name; ?>" type="checkbox" id="<?php echo $option_name; ?>" value="1" <?php if(get_option($option_name)==1) echo "checked='checked'"; ?>/> <?php echo $option_description; ?></label>
297
+ </fieldset> <?php
298
+ }
299
+
300
+ ?>
301
+
302
+ <div class="wrap">
303
+
304
+ <div id="icon-options-general" class="icon32"></div><h2>Video Thumbnails Options</h2>
305
+
306
+ <form method="post" action="options.php">
307
+ <?php wp_nonce_field('update-options'); ?>
308
+
309
+ <table class="form-table">
310
+
311
+ <tr valign="top">
312
+ <th scope="row">Save Thumbnail to Media</th>
313
+ <td><?php video_thumbnails_checkbox_option('video_thumbnails_save_media', 'Save local copies of thumbnails using the media library'); ?></td>
314
+ </tr>
315
+
316
+ <tr valign="top">
317
+ <th scope="row">Set as Featured Image</th>
318
+ <td><?php video_thumbnails_checkbox_option('video_thumbnails_set_featured', 'Automatically set thumbnail as featured image ("Save Thumbnail to Media" must be enabled)'); ?></td>
319
+ </tr>
320
+
321
+ </table>
322
+
323
+ <p class="submit">
324
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
325
+ </p>
326
+
327
+ <h3>How to use</h3>
328
+
329
+ <p>For themes that use featured images, simply leave the two settings above enabled.</p>
330
+
331
+ <p>For more detailed instructions, check out the page for <a href="http://wordpress.org/extend/plugins/video-thumbnails/">Video Thumbnails on the official plugin directory</a>.</p>
332
+
333
+ <input type="hidden" name="action" value="update" />
334
+ <input type="hidden" name="page_options" value="video_thumbnails_save_media,video_thumbnails_set_featured" />
335
+
336
+ </form>
337
+
338
+ <h3>Scan all posts</h3>
339
+
340
+ <p>Click to scan past posts for video thumbnails (this may take awhile)</p>
341
+ <?php
342
+
343
+ // If the button was clicked
344
+ if ( ! empty( $_POST['scan-for-thumbnails'] ) ) {
345
+ // Capability check
346
+ if ( !current_user_can( 'manage_options' ) )
347
+ wp_die( __( 'Cheatin&#8217; uh?' ) );
348
+
349
+ // Form nonce check
350
+ check_admin_referer( 'scan-for-thumbnails' );
351
+
352
+ query_posts('posts_per_page=-1');
353
+
354
+ $home_url = str_replace("/","\/",home_url());
355
+
356
+ echo '<p><ol>';
357
+ while (have_posts()) : the_post();
358
+ echo '<li>';
359
+ echo '<strong>' . get_the_title() . '</strong> - ';
360
+ if( ($video_thumbnail=get_video_thumbnail())!=null ) {
361
+ echo 'Found one, ';
362
+ if (preg_match('/^'.$home_url.'/', $video_thumbnail)) {
363
+ echo 'and it\'s already local.';
364
+ } else {
365
+ echo 'but it\'s remote. ';
366
+ if(delete_post_meta(get_the_ID(), '_video_thumbnail')) {
367
+ echo 'Remote file has been removed, ';
368
+ }
369
+ if( ($video_thumbnail=get_video_thumbnail())!=null ) {
370
+ echo 'and a local one has been created at ' . $video_thumbnail;
371
+ } else {
372
+ echo 'but no new one could be found. Did you remove the video?';
373
+ }
374
+ }
375
+ } else {
376
+ echo 'None found.';
377
+ }
378
+ echo '</li>';
379
+ endwhile;
380
+ echo '</ol></p>';
381
+
382
+ }
383
+
384
+ ?>
385
+
386
+ <form method="post" action="">
387
+ <?php wp_nonce_field('scan-for-thumbnails') ?>
388
+
389
+ <p><input type="submit" class="button" name="scan-for-thumbnails" id="scan-for-thumbnails" value="Scan for Video Thumbnails" /></p>
390
+
391
+ </form>
392
+
393
+
394
+ </div>
395
+
396
+ <?php
397
+
398
+ }
399
+
400
  ?>