Multiple Post Thumbnails - Version 0.4

Version Description

  • Added: optional argument $link_to_original to *_the_post_thumbnails template tags. Thanks to gfors for the suggestion.
  • Fixed: PHP warning in media manager due to non-existent object
Download this release

Release Info

Developer chrisscott
Plugin Icon wp plugin Multiple Post Thumbnails
Version 0.4
Comparing to
See all releases

Code changes from version 0.2 to 0.4

Files changed (2) hide show
  1. multi-post-thumbnails.php +18 -4
  2. readme.txt +9 -2
multi-post-thumbnails.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Multiple Post Thumbnails
4
  Plugin URI: http://vocecommunications.com/
5
  Description: Adds the ability to add multiple post thumbnails to a post type.
6
- Version: 0.2
7
  Author: Chris Scott
8
  Author URI: http://vocecommuncations.com/
9
  */
@@ -118,6 +118,13 @@ if (!class_exists('MultiPostThumbnails')) {
118
  $calling_post_id = absint($_GET['post_id']);
119
  elseif (isset($_POST) && count($_POST)) // Like for async-upload where $_GET['post_id'] isn't set
120
  $calling_post_id = $post->post_parent;
 
 
 
 
 
 
 
121
  $ajax_nonce = wp_create_nonce("set_post_thumbnail-{$this->post_type}-{$this->id}-{$calling_post_id}");
122
  $link = sprintf('<a id="%4$s-%1$s-thumbnail-%2$s" class="%1$s-thumbnail" href="#" onclick="MultiPostThumbnailsSetAsThumbnail(\'%2$s\', \'%1$s\', \'%4$s\', \'%5$s\');return false;">Set as %3$s</a>', $this->id, $post->ID, $this->label, $this->post_type, $ajax_nonce);
123
  $form_fields["{$this->post_type}-{$this->id}-thumbnail"] = array(
@@ -164,9 +171,10 @@ if (!class_exists('MultiPostThumbnails')) {
164
  * @param string $post_id Optional. Post ID.
165
  * @param int $size Optional. Image size. Defaults to 'post-thumbnail', which theme sets using set_post_thumbnail_size( $width, $height, $crop_flag );.
166
  * @param string|array $attr Optional. Query string or array of attributes.
 
167
  */
168
- public static function the_post_thumbnail($post_type, $id, $post_id = null, $size = 'post-thumbnail', $attr = '') {
169
- echo self::get_the_post_thumbnail($post_type, $id, $post_id, $size, $attr);
170
  }
171
 
172
  /**
@@ -176,9 +184,10 @@ if (!class_exists('MultiPostThumbnails')) {
176
  * @param string $id The id used to register the thumbnail.
177
  * @param int $post_id Optional. Post ID.
178
  * @param string $size Optional. Image size. Defaults to 'thumbnail'.
 
179
  * @param string|array $attr Optional. Query string or array of attributes.
180
  */
181
- public static function get_the_post_thumbnail($post_type, $thumb_id, $post_id = NULL, $size = 'post-thumbnail', $attr = '' ) {
182
  global $id;
183
  $post_id = (NULL === $post_id) ? $id : $post_id;
184
  $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $thumb_id, $post_id);
@@ -190,6 +199,11 @@ if (!class_exists('MultiPostThumbnails')) {
190
  } else {
191
  $html = '';
192
  }
 
 
 
 
 
193
  return apply_filters("{$post_type}_{$id}_thumbnail_html", $html, $post_id, $post_thumbnail_id, $size, $attr);
194
  }
195
 
3
  Plugin Name: Multiple Post Thumbnails
4
  Plugin URI: http://vocecommunications.com/
5
  Description: Adds the ability to add multiple post thumbnails to a post type.
6
+ Version: 0.4
7
  Author: Chris Scott
8
  Author URI: http://vocecommuncations.com/
9
  */
118
  $calling_post_id = absint($_GET['post_id']);
119
  elseif (isset($_POST) && count($_POST)) // Like for async-upload where $_GET['post_id'] isn't set
120
  $calling_post_id = $post->post_parent;
121
+
122
+ // check the post type to see if link needs to be added
123
+ $calling_post = get_post($calling_post_id);
124
+ if ($calling_post && $calling_post->post_type != $this->post_type) {
125
+ return $form_fields;
126
+ }
127
+
128
  $ajax_nonce = wp_create_nonce("set_post_thumbnail-{$this->post_type}-{$this->id}-{$calling_post_id}");
129
  $link = sprintf('<a id="%4$s-%1$s-thumbnail-%2$s" class="%1$s-thumbnail" href="#" onclick="MultiPostThumbnailsSetAsThumbnail(\'%2$s\', \'%1$s\', \'%4$s\', \'%5$s\');return false;">Set as %3$s</a>', $this->id, $post->ID, $this->label, $this->post_type, $ajax_nonce);
130
  $form_fields["{$this->post_type}-{$this->id}-thumbnail"] = array(
171
  * @param string $post_id Optional. Post ID.
172
  * @param int $size Optional. Image size. Defaults to 'post-thumbnail', which theme sets using set_post_thumbnail_size( $width, $height, $crop_flag );.
173
  * @param string|array $attr Optional. Query string or array of attributes.
174
+ * @param bool $link_to_original Optional. Wrap link to original image around thumbnail?
175
  */
176
+ public static function the_post_thumbnail($post_type, $id, $post_id = null, $size = 'post-thumbnail', $attr = '', $link_to_original = false) {
177
+ echo self::get_the_post_thumbnail($post_type, $id, $post_id, $size, $attr, $link_to_original);
178
  }
179
 
180
  /**
184
  * @param string $id The id used to register the thumbnail.
185
  * @param int $post_id Optional. Post ID.
186
  * @param string $size Optional. Image size. Defaults to 'thumbnail'.
187
+ * @param bool $link_to_original Optional. Wrap link to original image around thumbnail?
188
  * @param string|array $attr Optional. Query string or array of attributes.
189
  */
190
+ public static function get_the_post_thumbnail($post_type, $thumb_id, $post_id = NULL, $size = 'post-thumbnail', $attr = '' , $link_to_original = false) {
191
  global $id;
192
  $post_id = (NULL === $post_id) ? $id : $post_id;
193
  $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $thumb_id, $post_id);
199
  } else {
200
  $html = '';
201
  }
202
+
203
+ if ($link_to_original) {
204
+ $html = sprintf('<a href="%s">%s</a>', wp_get_attachment_url($post_thumbnail_id), $html);
205
+ }
206
+
207
  return apply_filters("{$post_type}_{$id}_thumbnail_html", $html, $post_id, $post_thumbnail_id, $size, $attr);
208
  }
209
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: chrisscott
3
  Tags: thumbnails, image
4
  Requires at least: 2.9.2
5
- Tested up to: 3.0
6
- Stable tag: 0.2
7
 
8
  Adds the ability to add multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
9
 
@@ -63,6 +63,13 @@ You can register multiple image sizes for a given thumbnail if desired.
63
 
64
  == Changelog ==
65
 
 
 
 
 
 
 
 
66
  = 0.2 =
67
  * Update docs and screenshots. Update tested through to 3.0 release.
68
 
2
  Contributors: chrisscott
3
  Tags: thumbnails, image
4
  Requires at least: 2.9.2
5
+ Tested up to: 3.0.1
6
+ Stable tag: 0.4
7
 
8
  Adds the ability to add multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
9
 
63
 
64
  == Changelog ==
65
 
66
+ = 0.4 =
67
+ * Added: optional argument `$link_to_original` to *_the_post_thumbnails template tags. Thanks to gfors for the suggestion.
68
+ * Fixed: PHP warning in media manager due to non-existent object
69
+
70
+ = 0.3 =
71
+ * Fixed: when displaying the insert link in the media library, check the post_type so it only shows for the registered type.
72
+
73
  = 0.2 =
74
  * Update docs and screenshots. Update tested through to 3.0 release.
75