Opened 12 years ago
Closed 12 years ago
#20409 closed enhancement (fixed)
XML-RPC returns only full-size URL for featured image
Reported by: | koke | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.4 | Priority: | normal |
Severity: | normal | Version: | 3.4 |
Component: | XML-RPC | Keywords: | |
Focuses: | Cc: |
Description
I'm not sure if having more than one featured_image url would be too much for getPost (and similar calls), since there are also media library calls, but if there's going to be any, maybe the thumbnail size url would be more relevant
Attachments (5)
Change History (22)
#3
@
12 years ago
- Cc markoheijnen added
What about wp_get_attachment_thumb_url(). Seems like in this case that should work to.
That said wp_get_attachment_image() is a better way since it also can give the possibility to change the size when needed. Maybe not know but for future possibilities.
#4
@
12 years ago
- Cc maxcutler added
Another alternative is to extract most of wp_getMediaItem
into a _prepare_media_item
method and use that for featured_image
in _prepare_post
instead of an ID and a separate additional field.
That way you would have wp_getMediaItem
, wp_getMediaLibrary
, and _prepare_post
all returning image/attachment data in an identical and filter-able format. And you'd solve the re-querying performance hit with wp_getMediaLibrary
.
We are already doing this for terms in _prepare_post
.
If others like this, I can draw up a patch and unit tests tonight.
#6
@
12 years ago
Sure. It's worth mentioning that wp_get_attachment_thumb_url() uses a size of 'thumbnail' while post thumbnails are a particular 'post-thumbnail' size. So you still may need to use wp_get_attachment_image() with a $size.
#7
@
12 years ago
Added a patch for my suggestion above. Now posts will have a post_thumbnail
field which is an array containing the same values as would be gotten from wp.getMediaItem
(or an empty array if there's no thumbnail).
As suggested by nacin, the thumbnail URL will use 'post-thumbnail' size if the theme supports it, and fall back to 'thumbnail' otherwise.
Also added basic tests in [UT693] to cover the existing wp.getMediaItem
/wp.getMediaLibrary behavior
so that we don't break that.
#8
@
12 years ago
I think we can drop the extra underscore from the xmlrpc__prepare_media_item filter.
#9
@
12 years ago
Refreshed patch after comments in IRC:
- Replaced
get_post_meta
calls withget_post_thumbnail_id
- Removed 'wp_post_thumbnail_url' from the legacy methods.
- Replaced one-line if statement with a ternary statement.
Will create another ticket for the extra underscores that ryan mentioned.
#10
@
12 years ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In [20608]:
#11
@
12 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
post-thumbnail-template.php is conditionally loaded based upon whether the theme supports post-thumbnails. If the theme does not, get_post_thumbnail_id() is undefined and results in fatal errors.
#12
@
12 years ago
We can either always load post-thumbnail-template.php or move get_post_thumbnail_id() and perhaps has_post_thumbnail() to post.php.
#13
@
12 years ago
I would prefer moving get_post_thumbnail_id. Would make sense since updating and removing can be done when theme doesn't supports post-thumbnails
#14
@
12 years ago
I'm leaning that way myself. Anyone want to patch it up and test? Perhaps we could cajole the unit tests into running with and without post-thumbnail support enabled.
Indeed, it would make more sense if only the thumbnail size was returned.
We don't yet have get_the_post_thumbnail_src() yet — #11571. But we can simply call wp_get_attachment_image() with $size = 'post-thumbnail'.