Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get thumbnail title and description #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
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
40 changes: 40 additions & 0 deletions multi-post-thumbnails.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,46 @@ 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I didn't notice this earlier, but can you default $post_id to null so that it is an optional arg and makes sense w/the below conditional? e.g. similar to get_post_thumnail_url()

if (!$post_id) {
$post_id = get_the_ID();
}
$post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id);
if ($post_thumbnail_id) {
$attachment_meta = get_post($post_thumbnail_id);
$attachment_title = $attachment_meta->post_title;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be a bit cleaner to set the default for $attachment_title before the conditional so then the else isn't needed here. Likewise on L411 below.

$attachment_title = '';
}
return $attachment_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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Like above, can you default $post_id to null?

if (!$post_id) {
$post_id = get_the_ID();
}
$post_thumbnail_id = self::get_post_thumbnail_id($post_type, $id, $post_id);
if ($post_thumbnail_id) {
$attachment_meta = get_post($post_thumbnail_id);
$attachment_excerpt = $attachment_meta->post_excerpt;
} else {
$attachment_excerpt = '';
}
return $attachment_excerpt;
}

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