Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions multi-post-thumbnails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Can you check to make sure $post_thumbnail_id is valid here before doing get_post()? Making sure it is an int greater than zero should cover it. If it isn't valid, returning a blank string seems appropriate.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like above an you check to make sure $post_thumbnail_id is valid here before doing get_post() and returning a blank string if not?

return $attachment_meta->post_excerpt;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use get_the_excerpt() here? It would apply the excerpt filters which seems appropriate as well as check for private posts to prevent information disclosure where it isn't desired. If so, this would negate my comment above.

}

/**
* Output the post thumbnail HTML for the metabox and AJAX callbacks
Expand Down