Version Description
- Use
get_the_ID()
inget_the_post_thumbnail
. Props helgatheviking.
Download this release
Release Info
Developer | chrisscott |
Plugin | Multiple Post Thumbnails |
Version | 1.0 |
Comparing to | |
See all releases |
Code changes from version 0.9 to 1.0
- multi-post-thumbnails.php +34 -3
- readme.txt +14 -10
multi-post-thumbnails.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Multiple Post Thumbnails
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/multiple-post-thumbnails/
|
5 |
Description: Adds the ability to add multiple post thumbnails to a post type.
|
6 |
-
Version: 0
|
7 |
Author: Chris Scott
|
8 |
Author URI: http://vocecommuncations.com/
|
9 |
*/
|
@@ -83,6 +83,7 @@ if (!class_exists('MultiPostThumbnails')) {
|
|
83 |
add_filter('attachment_fields_to_edit', array($this, 'add_attachment_field'), 20, 2);
|
84 |
add_action('admin_init', array($this, 'enqueue_admin_scripts'));
|
85 |
add_action("wp_ajax_set-{$this->post_type}-{$this->id}-thumbnail", array($this, 'set_thumbnail'));
|
|
|
86 |
}
|
87 |
|
88 |
/**
|
@@ -143,6 +144,19 @@ if (!class_exists('MultiPostThumbnails')) {
|
|
143 |
wp_enqueue_script("featured-image-custom", $this->plugins_url('js/multi-post-thumbnails-admin.js', __FILE__), array('jquery'));
|
144 |
}
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
private function plugins_url($relative_path, $plugin_path) {
|
147 |
$template_dir = get_template_directory();
|
148 |
|
@@ -211,7 +225,7 @@ if (!class_exists('MultiPostThumbnails')) {
|
|
211 |
*/
|
212 |
public static function get_the_post_thumbnail($post_type, $thumb_id, $post_id = NULL, $size = 'post-thumbnail', $attr = '' , $link_to_original = false) {
|
213 |
global $id;
|
214 |
-
$post_id = (NULL === $post_id) ?
|
215 |
$post_thumbnail_id = self::get_post_thumbnail_id($post_type, $thumb_id, $post_id);
|
216 |
$size = apply_filters("{$post_type}_{$post_id}_thumbnail_size", $size);
|
217 |
if ($post_thumbnail_id) {
|
@@ -234,13 +248,30 @@ if (!class_exists('MultiPostThumbnails')) {
|
|
234 |
*
|
235 |
* @param string $post_type The post type.
|
236 |
* @param string $id The id used to register the thumbnail.
|
237 |
-
* @param int $post_id
|
238 |
* @return int
|
239 |
*/
|
240 |
public static function get_post_thumbnail_id($post_type, $id, $post_id) {
|
241 |
return get_post_meta($post_id, "{$post_type}_{$id}_thumbnail_id", true);
|
242 |
}
|
243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
/**
|
245 |
* Output the post thumbnail HTML for the metabox and AJAX callbacks
|
246 |
*
|
3 |
Plugin Name: Multiple Post Thumbnails
|
4 |
Plugin URI: http://wordpress.org/extend/plugins/multiple-post-thumbnails/
|
5 |
Description: Adds the ability to add multiple post thumbnails to a post type.
|
6 |
+
Version: 1.0
|
7 |
Author: Chris Scott
|
8 |
Author URI: http://vocecommuncations.com/
|
9 |
*/
|
83 |
add_filter('attachment_fields_to_edit', array($this, 'add_attachment_field'), 20, 2);
|
84 |
add_action('admin_init', array($this, 'enqueue_admin_scripts'));
|
85 |
add_action("wp_ajax_set-{$this->post_type}-{$this->id}-thumbnail", array($this, 'set_thumbnail'));
|
86 |
+
add_action('delete_attachment', array($this, 'action_delete_attachment'));
|
87 |
}
|
88 |
|
89 |
/**
|
144 |
wp_enqueue_script("featured-image-custom", $this->plugins_url('js/multi-post-thumbnails-admin.js', __FILE__), array('jquery'));
|
145 |
}
|
146 |
|
147 |
+
/**
|
148 |
+
* Deletes the post meta data for posts when an attachment used as a
|
149 |
+
* multiple post thumbnail is deleted from the Media Libray
|
150 |
+
*
|
151 |
+
* @global object $wpdb
|
152 |
+
* @param int $post_id
|
153 |
+
*/
|
154 |
+
public function action_delete_attachment($post_id) {
|
155 |
+
global $wpdb;
|
156 |
+
$meta_key = "{$this->post_type}_{$this->id}_thumbnail_id";
|
157 |
+
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = '%s' AND meta_value = %d", $meta_key, $post_id ));
|
158 |
+
}
|
159 |
+
|
160 |
private function plugins_url($relative_path, $plugin_path) {
|
161 |
$template_dir = get_template_directory();
|
162 |
|
225 |
*/
|
226 |
public static function get_the_post_thumbnail($post_type, $thumb_id, $post_id = NULL, $size = 'post-thumbnail', $attr = '' , $link_to_original = false) {
|
227 |
global $id;
|
228 |
+
$post_id = (NULL === $post_id) ? get_the_ID() : $post_id;
|
229 |
$post_thumbnail_id = self::get_post_thumbnail_id($post_type, $thumb_id, $post_id);
|
230 |
$size = apply_filters("{$post_type}_{$post_id}_thumbnail_size", $size);
|
231 |
if ($post_thumbnail_id) {
|
248 |
*
|
249 |
* @param string $post_type The post type.
|
250 |
* @param string $id The id used to register the thumbnail.
|
251 |
+
* @param int $post_id Post ID.
|
252 |
* @return int
|
253 |
*/
|
254 |
public static function get_post_thumbnail_id($post_type, $id, $post_id) {
|
255 |
return get_post_meta($post_id, "{$post_type}_{$id}_thumbnail_id", true);
|
256 |
}
|
257 |
|
258 |
+
/**
|
259 |
+
*
|
260 |
+
* @param string $post_type The post type.
|
261 |
+
* @param string $id The id used to register the thumbnail.
|
262 |
+
* @param int $post_id Optional. The post ID. If not set, will attempt to get it.
|
263 |
+
* @return mixed Thumbnail url or false if the post doesn't have a thumbnail for the given post type, and id.
|
264 |
+
*/
|
265 |
+
public static function get_post_thumbnail_url($post_type, $id, $post_id = 0) {
|
266 |
+
if (!$post_id) {
|
267 |
+
$post_id = get_the_ID();
|
268 |
+
}
|
269 |
+
|
270 |
+
$post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id);
|
271 |
+
|
272 |
+
return wp_get_attachment_url($post_thumbnail_id);
|
273 |
+
}
|
274 |
+
|
275 |
/**
|
276 |
* Output the post thumbnail HTML for the metabox and AJAX callbacks
|
277 |
*
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: chrisscott
|
|
3 |
Tags: thumbnails, image
|
4 |
Requires at least: 2.9.2
|
5 |
Tested up to: 3.2.1
|
6 |
-
Stable tag: 0
|
7 |
|
8 |
Adds 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 |
|
@@ -13,14 +13,14 @@ Adds multiple post thumbnails to a post type. If you've ever wanted more than on
|
|
13 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
14 |
3. Register a new thumbnail for the post type you want it active for. If `post_type` is not set it defaults to `post`.
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
4. Display the thumbnail in your theme:
|
25 |
|
26 |
<?php if (class_exists('MultiPostThumbnails')
|
@@ -69,6 +69,10 @@ You can register multiple image sizes for a given thumbnail if desired.
|
|
69 |
|
70 |
== Changelog ==
|
71 |
|
|
|
|
|
|
|
|
|
72 |
= 0.9 =
|
73 |
* Increment version only to attempt to get plugin versions back in sync.
|
74 |
|
@@ -101,4 +105,4 @@ You can register multiple image sizes for a given thumbnail if desired.
|
|
101 |
== Upgrade Notice ==
|
102 |
|
103 |
= 0.6 =
|
104 |
-
`get_the_post_thumbnail` return filter changed to use the format `{$post_type}_{$thumb_id}_thumbnail_html` which allows filtering by post type and thumbnail id which was the intent.
|
3 |
Tags: thumbnails, image
|
4 |
Requires at least: 2.9.2
|
5 |
Tested up to: 3.2.1
|
6 |
+
Stable tag: 1.0
|
7 |
|
8 |
Adds 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 |
|
13 |
2. Activate the plugin through the 'Plugins' menu in WordPress
|
14 |
3. Register a new thumbnail for the post type you want it active for. If `post_type` is not set it defaults to `post`.
|
15 |
|
16 |
+
if (class_exists('MultiPostThumbnails')) {
|
17 |
+
new MultiPostThumbnails(array(
|
18 |
+
'label' => 'Secondary Image',
|
19 |
+
'id' => 'secondary-image',
|
20 |
+
'post_type' => 'post'
|
21 |
+
)
|
22 |
+
);
|
23 |
+
}
|
24 |
4. Display the thumbnail in your theme:
|
25 |
|
26 |
<?php if (class_exists('MultiPostThumbnails')
|
69 |
|
70 |
== Changelog ==
|
71 |
|
72 |
+
= 1.0 =
|
73 |
+
|
74 |
+
* Use `get_the_ID()` in `get_the_post_thumbnail`. Props helgatheviking.
|
75 |
+
|
76 |
= 0.9 =
|
77 |
* Increment version only to attempt to get plugin versions back in sync.
|
78 |
|
105 |
== Upgrade Notice ==
|
106 |
|
107 |
= 0.6 =
|
108 |
+
`get_the_post_thumbnail` return filter changed to use the format `{$post_type}_{$thumb_id}_thumbnail_html` which allows filtering by post type and thumbnail id which was the intent.
|