From 198e7dbca9fad676e7fe704d96999dd0e7a0208d Mon Sep 17 00:00:00 2001 From: Vladimir Sobolev Date: Wed, 6 Jul 2016 11:52:23 -0400 Subject: [PATCH 1/3] get thumbnail title and description --- multi-post-thumbnails.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/multi-post-thumbnails.php b/multi-post-thumbnails.php index 817d49d..f48a683 100644 --- a/multi-post-thumbnails.php +++ b/multi-post-thumbnails.php @@ -372,6 +372,32 @@ public static function get_post_thumbnail_url($post_type, $id, $post_id = 0, $si return $url; } + + /** + * + * @param string $post_type The post type. + * @param string $id The id used to register the thumbnail. + * @return thumbnail title. + */ + public static function get_post_thumbnail_title($post_type, $id) { + $post_id = get_the_ID(); + $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id); + $attachment_meta = get_post($post_thumbnail_id); + return $attachment_meta->post_title; + } + + /** + * + * @param string $post_type The post type. + * @param string $id The id used to register the thumbnail. + * @return thumbnail description. + */ + public static function get_post_thumbnail_description($post_type, $id) { + $post_id = get_the_ID(); + $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id); + $attachment_meta = get_post($post_thumbnail_id); + return $attachment_meta->post_excerpt; + } /** * Output the post thumbnail HTML for the metabox and AJAX callbacks From 1d59b3a51c0bccd6b0e991a0c1ef053864c71bb4 Mon Sep 17 00:00:00 2001 From: Vladimir Sobolev Date: Thu, 7 Jul 2016 10:05:40 -0400 Subject: [PATCH 2/3] Check post_id is valid --- multi-post-thumbnails.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/multi-post-thumbnails.php b/multi-post-thumbnails.php index f48a683..e4c3cad 100644 --- a/multi-post-thumbnails.php +++ b/multi-post-thumbnails.php @@ -373,17 +373,24 @@ public static function get_post_thumbnail_url($post_type, $id, $post_id = 0, $si return $url; } - /** + /** * * @param string $post_type The post type. * @param string $id The id used to register the thumbnail. * @return thumbnail title. */ - public static function get_post_thumbnail_title($post_type, $id) { - $post_id = get_the_ID(); + public static function get_post_thumbnail_title($post_type, $id, $post_id) { + if (!$post_id) { + $post_id = get_the_ID(); + } $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id); - $attachment_meta = get_post($post_thumbnail_id); - return $attachment_meta->post_title; + if ($post_thumbnail_id) { + $attachment_meta = get_post($post_thumbnail_id); + $attachment_title = $attachment_meta->post_title; + } else { + $attachment_title = ''; + } + return $attachment_title; } /** @@ -392,11 +399,18 @@ public static function get_post_thumbnail_title($post_type, $id) { * @param string $id The id used to register the thumbnail. * @return thumbnail description. */ - public static function get_post_thumbnail_description($post_type, $id) { - $post_id = get_the_ID(); + public static function get_post_thumbnail_description($post_type, $id, $post_id) { + if (!$post_id) { + $post_id = get_the_ID(); + } $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id); - $attachment_meta = get_post($post_thumbnail_id); - return $attachment_meta->post_excerpt; + if ($post_thumbnail_id) { + $attachment_meta = get_post($post_thumbnail_id); + $attachment_excerpt = $attachment_meta->post_excerpt; + } else { + $attachment_excerpt = ''; + } + return $attachment_excerpt; } /** From dadcc829cec6615b06ff33ad937cbfacac0615ac Mon Sep 17 00:00:00 2001 From: Vladimir Sobolev Date: Mon, 11 Jul 2016 13:21:34 -0400 Subject: [PATCH 3/3] Defaults for post id, attachment excerpt and title --- multi-post-thumbnails.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/multi-post-thumbnails.php b/multi-post-thumbnails.php index e4c3cad..bd8b3b8 100644 --- a/multi-post-thumbnails.php +++ b/multi-post-thumbnails.php @@ -379,16 +379,15 @@ public static function get_post_thumbnail_url($post_type, $id, $post_id = 0, $si * @param string $id The id used to register the thumbnail. * @return thumbnail title. */ - public static function get_post_thumbnail_title($post_type, $id, $post_id) { + public static function get_post_thumbnail_title($post_type, $id, $post_id = null) { if (!$post_id) { $post_id = get_the_ID(); } $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id); + $attachment_title = ''; if ($post_thumbnail_id) { $attachment_meta = get_post($post_thumbnail_id); $attachment_title = $attachment_meta->post_title; - } else { - $attachment_title = ''; } return $attachment_title; } @@ -399,16 +398,15 @@ public static function get_post_thumbnail_title($post_type, $id, $post_id) { * @param string $id The id used to register the thumbnail. * @return thumbnail description. */ - public static function get_post_thumbnail_description($post_type, $id, $post_id) { + public static function get_post_thumbnail_description($post_type, $id, $post_id = null) { if (!$post_id) { $post_id = get_the_ID(); } $post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id); + $attachment_excerpt = ''; if ($post_thumbnail_id) { $attachment_meta = get_post($post_thumbnail_id); $attachment_excerpt = $attachment_meta->post_excerpt; - } else { - $attachment_excerpt = ''; } return $attachment_excerpt; }