Version Description
- Thumbnail URLs are now stored in a custom field with each post, meaning the plugin only has to interact with outside APIs once per post.
- Added a "Video Thumbnail" meta box to the edit screen for each post, which can be manually set or will be set automatically once
video_thumbnail()
orget_video_thumbnail()
is called in a loop for that post.
Download this release
Release Info
Developer | sutherlandboswell |
Plugin | Video Thumbnails |
Version | 0.5 |
Comparing to | |
See all releases |
Code changes from version 0.3 to 0.5
- readme.txt +21 -10
- screenshot-1.gif +0 -0
- video-thumbnails.php +106 -58
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Video Thumbnails ===
|
2 |
Contributors: sutherlandboswell
|
3 |
Donate link: http://sutherlandboswell.com
|
4 |
-
Tags: Video, YouTube, Vimeo, Thumbnails
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.0.1
|
7 |
-
Stable tag: 0.
|
8 |
|
9 |
Video Thumbnails is a simple plugin that makes it easier to display video thumbnails in your template.
|
10 |
|
@@ -24,8 +24,6 @@ When using `video_thumbnail()` and no thumbnail is found, a default thumbnail is
|
|
24 |
|
25 |
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 . "' />"; } ?>`
|
26 |
|
27 |
-
This is just a start, so don't hesitate to share suggestions and let me know if you find any problems.
|
28 |
-
|
29 |
== Installation ==
|
30 |
|
31 |
1. Upload the `/video-thumbnails/` directory to the `/wp-content/plugins/` directory
|
@@ -34,7 +32,11 @@ This is just a start, so don't hesitate to share suggestions and let me know if
|
|
34 |
|
35 |
== Frequently Asked Questions ==
|
36 |
|
37 |
-
=
|
|
|
|
|
|
|
|
|
38 |
|
39 |
If the service allows a way to retrieve thumbnails, I'll do my best to add it.
|
40 |
|
@@ -44,10 +46,14 @@ In version 0.2 `get_video_thumbnail()` was added which returns null when no thum
|
|
44 |
|
45 |
== Screenshots ==
|
46 |
|
47 |
-
|
48 |
|
49 |
== Changelog ==
|
50 |
|
|
|
|
|
|
|
|
|
51 |
= 0.3 =
|
52 |
* Added basic support for Blip.tv auto embedded using URLs in this format: http://blip.tv/file/12345
|
53 |
|
@@ -76,16 +82,21 @@ Coming Soon
|
|
76 |
= 0.1 =
|
77 |
* Initial release
|
78 |
|
|
|
|
|
|
|
|
|
|
|
79 |
== Known Issues ==
|
80 |
|
81 |
-
*
|
82 |
-
* While not really an issue, the current method for only displaying a thumbnail if one is found seems like it could be streamlined, so if you have any suggestions let me know.
|
83 |
|
84 |
== Roadmap ==
|
85 |
|
86 |
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:
|
87 |
|
88 |
* More comprehensive Blip.tv support
|
89 |
-
* Local thumbnail
|
90 |
* More services
|
91 |
-
*
|
1 |
=== Video Thumbnails ===
|
2 |
Contributors: sutherlandboswell
|
3 |
Donate link: http://sutherlandboswell.com
|
4 |
+
Tags: Video, YouTube, Vimeo, Blip.tv, Thumbnails
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.0.1
|
7 |
+
Stable tag: 0.5
|
8 |
|
9 |
Video Thumbnails is a simple plugin that makes it easier to display video thumbnails in your template.
|
10 |
|
24 |
|
25 |
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 . "' />"; } ?>`
|
26 |
|
|
|
|
|
27 |
== Installation ==
|
28 |
|
29 |
1. Upload the `/video-thumbnails/` directory to the `/wp-content/plugins/` directory
|
32 |
|
33 |
== Frequently Asked Questions ==
|
34 |
|
35 |
+
= Why doesn't the thumbnail show up in the meta box on the Edit Post page after I save it? =
|
36 |
+
|
37 |
+
This is probably happening because `video_thumbnail()` or `get_video_thumbnail()` has not be used in a loop for that post yet. Try loading a page that calls for the thumbnail then checking the Edit Post page again. This will be fixed in a future version.
|
38 |
+
|
39 |
+
= My video service/embedding plugin isn't included, can you add it? =
|
40 |
|
41 |
If the service allows a way to retrieve thumbnails, I'll do my best to add it.
|
42 |
|
46 |
|
47 |
== Screenshots ==
|
48 |
|
49 |
+
1. The Video Thumbnail meta box on the Edit Post page
|
50 |
|
51 |
== Changelog ==
|
52 |
|
53 |
+
= 0.5 =
|
54 |
+
* Thumbnail URLs are now stored in a custom field with each post, meaning the plugin only has to interact with outside APIs once per post.
|
55 |
+
* Added a "Video Thumbnail" meta box to the edit screen for each post, which can be manually set or will be set automatically once `video_thumbnail()` or `get_video_thumbnail()` is called in a loop for that post.
|
56 |
+
|
57 |
= 0.3 =
|
58 |
* Added basic support for Blip.tv auto embedded using URLs in this format: http://blip.tv/file/12345
|
59 |
|
82 |
= 0.1 =
|
83 |
* Initial release
|
84 |
|
85 |
+
== Upgrade Notice ==
|
86 |
+
|
87 |
+
= 0.5 =
|
88 |
+
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.
|
89 |
+
|
90 |
== Known Issues ==
|
91 |
|
92 |
+
* Thumbnail URLs are not found and stored until `video_thumbnail()` or `get_video_thumbnail()` is called in a loop for that post. Future versions will handle this at the time of publishing.
|
93 |
+
* While not really an issue, the current method for only displaying a thumbnail if one is found seems like it could be streamlined for less experienced users, so if you have any suggestions let me know.
|
94 |
|
95 |
== Roadmap ==
|
96 |
|
97 |
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:
|
98 |
|
99 |
* More comprehensive Blip.tv support
|
100 |
+
* Local thumbnail caching
|
101 |
* More services
|
102 |
+
* Compatibility with more plugins
|
screenshot-1.gif
ADDED
Binary file
|
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: A plugin designed to fetch video thumbnails.
|
6 |
Author: Sutherland Boswell
|
7 |
Author URI: http://sutherlandboswell.com
|
8 |
-
Version: 0.
|
9 |
License: GPL2
|
10 |
*/
|
11 |
/* Copyright 2010 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
@@ -42,83 +42,98 @@ function getVimeoInfo($id, $info = 'thumbnail_large') {
|
|
42 |
function getBliptvInfo($id) {
|
43 |
$xml = simplexml_load_file("http://blip.tv/file/$id?skin=rss");
|
44 |
$result = $xml->xpath("/rss/channel/item/media:thumbnail/@url");
|
45 |
-
|
46 |
-
$thumbnail = $element["url"];
|
47 |
-
}
|
48 |
return $thumbnail;
|
49 |
}
|
50 |
|
51 |
// The Main Event
|
52 |
function get_video_thumbnail() {
|
53 |
-
|
54 |
-
// Gets the post's content
|
55 |
-
$markup = get_the_content();
|
56 |
-
|
57 |
-
// Checks for a standard YouTube embed
|
58 |
-
preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
|
59 |
-
|
60 |
-
// Checks for any YouTube URL
|
61 |
-
if(!isset($matches[1])) {
|
62 |
-
preg_match('#http://www.youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches);
|
63 |
-
}
|
64 |
|
65 |
-
//
|
66 |
-
|
67 |
-
|
|
|
68 |
}
|
69 |
-
|
70 |
-
// If we've found a YouTube video ID, return the thumbnail URL
|
71 |
-
if(isset($matches[1])) {
|
72 |
-
return 'http://img.youtube.com/vi/' . $matches[1] . '/0.jpg';
|
73 |
-
}
|
74 |
-
|
75 |
-
// If we didn't find anything, check for a standard Vimeo embed
|
76 |
else {
|
77 |
-
|
|
|
|
|
|
|
78 |
|
79 |
-
//
|
|
|
|
|
|
|
80 |
if(!isset($matches[1])) {
|
81 |
-
preg_match('#http://
|
82 |
}
|
83 |
|
84 |
-
// If
|
85 |
-
if(!isset($matches[1])) {
|
86 |
-
preg_match('#\[vimeo id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
|
87 |
-
}
|
88 |
-
|
89 |
-
// If we still haven't found anything, check for Vimeo URL
|
90 |
-
if(!isset($matches[1])) {
|
91 |
-
preg_match('#http://www.vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
|
92 |
-
}
|
93 |
-
|
94 |
-
// If we still haven't found anything, check for Vimeo shortcode
|
95 |
if(!isset($matches[1])) {
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
//
|
100 |
if(isset($matches[1])) {
|
101 |
-
$
|
102 |
-
if(isset($vimeo_thumbnail)) {
|
103 |
-
return $vimeo_thumbnail;
|
104 |
-
} else {
|
105 |
-
// If we can't find the Vimeo thumbnail, display default
|
106 |
-
return null;
|
107 |
-
}
|
108 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
if(isset($matches[1])) {
|
114 |
-
|
|
|
|
|
|
|
115 |
}
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
}
|
119 |
}
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
121 |
|
|
|
122 |
};
|
123 |
|
124 |
// Echo thumbnail
|
@@ -127,4 +142,37 @@ function video_thumbnail() {
|
|
127 |
else { echo $video_thumbnail; }
|
128 |
};
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
?>
|
2 |
/*
|
3 |
Plugin Name: Video Thumbnails
|
4 |
Plugin URI: http://sutherlandboswell.com/2010/11/wordpress-video-thumbnails/
|
5 |
+
Description: A plugin designed to fetch video thumbnails. Add <code><?php video_thumbnail(); ?></code> to your loop to return a thumbnail, or check the FAQ section for more advanced uses. Currently works with YouTube, Vimeo, and Blip.tv, with other services coming soon.
|
6 |
Author: Sutherland Boswell
|
7 |
Author URI: http://sutherlandboswell.com
|
8 |
+
Version: 0.5
|
9 |
License: GPL2
|
10 |
*/
|
11 |
/* Copyright 2010 Sutherland Boswell (email : sutherland.boswell@gmail.com)
|
42 |
function getBliptvInfo($id) {
|
43 |
$xml = simplexml_load_file("http://blip.tv/file/$id?skin=rss");
|
44 |
$result = $xml->xpath("/rss/channel/item/media:thumbnail/@url");
|
45 |
+
$thumbnail = (string) $result[0]['url'];
|
|
|
|
|
46 |
return $thumbnail;
|
47 |
}
|
48 |
|
49 |
// The Main Event
|
50 |
function get_video_thumbnail() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
// Check to see if thumbnail has already been found
|
53 |
+
$postid = get_the_ID();
|
54 |
+
if( ($thumbnail_meta = get_post_meta($postid, '_video_thumbnail', true)) != '' ) {
|
55 |
+
return $thumbnail_meta;
|
56 |
}
|
57 |
+
// If the thumbnail isn't stored in custom meta, fetch a thumbnail
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
else {
|
59 |
+
|
60 |
+
// Gets the post's content
|
61 |
+
$markup = get_the_content();
|
62 |
+
$new_thumbnail = null;
|
63 |
|
64 |
+
// Checks for a standard YouTube embed
|
65 |
+
preg_match('#<object[^>]+>.+?http://www.youtube.com/v/([A-Za-z0-9\-_]+).+?</object>#s', $markup, $matches);
|
66 |
+
|
67 |
+
// Checks for any YouTube URL
|
68 |
if(!isset($matches[1])) {
|
69 |
+
preg_match('#http://w?w?w?.?youtube.com/watch\?v=([A-Za-z0-9\-_]+)#s', $markup, $matches);
|
70 |
}
|
71 |
|
72 |
+
// If no standard YouTube embed is found, checks for one embedded with JR_embed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
if(!isset($matches[1])) {
|
74 |
+
preg_match('#\[youtube id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
|
75 |
+
}
|
76 |
+
|
77 |
+
// If we've found a YouTube video ID, create the thumbnail URL
|
78 |
if(isset($matches[1])) {
|
79 |
+
$new_thumbnail = 'http://img.youtube.com/vi/' . $matches[1] . '/0.jpg';
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
}
|
81 |
+
|
82 |
+
// Vimeo
|
83 |
+
if($new_thumbnail==null) {
|
84 |
+
|
85 |
+
// Standard embed code
|
86 |
+
preg_match('#<object[^>]+>.+?http://vimeo.com/moogaloop.swf\?clip_id=([A-Za-z0-9\-_]+)&.+?</object>#s', $markup, $matches);
|
87 |
+
|
88 |
+
// Find Vimeo embedded with iframe code
|
89 |
+
if(!isset($matches[1])) {
|
90 |
+
preg_match('#http://player.vimeo.com/video/([0-9]+)#s', $markup, $matches);
|
91 |
+
}
|
92 |
+
|
93 |
+
// If we still haven't found anything, check for Vimeo embedded with JR_embed
|
94 |
+
if(!isset($matches[1])) {
|
95 |
+
preg_match('#\[vimeo id=([A-Za-z0-9\-_]+)]#s', $markup, $matches);
|
96 |
+
}
|
97 |
|
98 |
+
// If we still haven't found anything, check for Vimeo URL
|
99 |
+
if(!isset($matches[1])) {
|
100 |
+
preg_match('#http://w?w?w?.?vimeo.com/([A-Za-z0-9\-_]+)#s', $markup, $matches);
|
101 |
+
}
|
102 |
+
|
103 |
+
// If we still haven't found anything, check for Vimeo shortcode
|
104 |
+
if(!isset($matches[1])) {
|
105 |
+
preg_match('#\[vimeo clip_id="([A-Za-z0-9\-_]+)"[^>]*]#s', $markup, $matches);
|
106 |
+
}
|
107 |
+
|
108 |
+
// Now if we've found a Vimeo ID, let's set the thumbnail URL
|
109 |
if(isset($matches[1])) {
|
110 |
+
$vimeo_thumbnail = getVimeoInfo($matches[1], $info = 'thumbnail_large');
|
111 |
+
if(isset($vimeo_thumbnail)) {
|
112 |
+
$new_thumbnail = $vimeo_thumbnail;
|
113 |
+
}
|
114 |
}
|
115 |
+
}
|
116 |
+
|
117 |
+
// Blip.tv
|
118 |
+
if($new_thumbnail==null) {
|
119 |
+
|
120 |
+
// Blip.tv file URL
|
121 |
+
preg_match('#http://blip.tv/file/([0-9]+)#s', $markup, $matches);
|
122 |
+
|
123 |
+
// Now if we've found a Blip.tv file URL, let's set the thumbnail URL
|
124 |
+
if(isset($matches[1])) {
|
125 |
+
$blip_thumbnail = getBliptvInfo($matches[1]);
|
126 |
+
$new_thumbnail = $blip_thumbnail;
|
127 |
}
|
128 |
}
|
129 |
+
|
130 |
+
// Return the new thumbnail variable and update meta if one is found
|
131 |
+
if($new_thumbnail!=null) {
|
132 |
+
if(!update_post_meta($postid, '_video_thumbnail', $new_thumbnail)) add_post_meta($postid, '_video_thumbnail', $new_thumbnail);
|
133 |
+
}
|
134 |
+
return $new_thumbnail;
|
135 |
|
136 |
+
}
|
137 |
};
|
138 |
|
139 |
// Echo thumbnail
|
142 |
else { echo $video_thumbnail; }
|
143 |
};
|
144 |
|
145 |
+
// Create Meta Fields on Edit Page
|
146 |
+
|
147 |
+
add_action("admin_init", "admin_init");
|
148 |
+
|
149 |
+
function admin_init(){
|
150 |
+
add_meta_box("video_thumbnail", "Video Thumbnail", "video_thumbnail_admin", "post", "side", "low");
|
151 |
+
}
|
152 |
+
|
153 |
+
function video_thumbnail_admin(){
|
154 |
+
global $post;
|
155 |
+
$custom = get_post_custom($post->ID);
|
156 |
+
$video_thumbnail = $custom["_video_thumbnail"][0];
|
157 |
+
?>
|
158 |
+
<p><label>Video Thumbnail URL:</label></p>
|
159 |
+
<p><input type="text" size="16" name="video_thumbnail" style="width:250px;" value="<?php echo $video_thumbnail; ?>" /></p>
|
160 |
+
<?php if(isset($video_thumbnail) && $video_thumbnail!='') { ?><p><img src="<?php echo $video_thumbnail; ?>" width="100%" /></p><?php } ?>
|
161 |
+
<?php
|
162 |
+
}
|
163 |
+
|
164 |
+
// Save Meta Details
|
165 |
+
|
166 |
+
add_action('save_post', 'save_details');
|
167 |
+
|
168 |
+
function save_details(){
|
169 |
+
global $post;
|
170 |
+
if(isset($_POST["video_thumbnail"]) && $_POST["video_thumbnail"]!='') {
|
171 |
+
if(!update_post_meta($post->ID, "_video_thumbnail", $_POST["video_thumbnail"])) add_post_meta($post->ID, "_video_thumbnail", $_POST["video_thumbnail"]);
|
172 |
+
}
|
173 |
+
if(isset($_POST["video_thumbnail"]) && $_POST["video_thumbnail"]=='') {
|
174 |
+
delete_post_meta($post->ID, "_video_thumbnail");
|
175 |
+
}
|
176 |
+
}
|
177 |
+
|
178 |
?>
|