Opened 14 months ago
Closed 13 months ago
#20409 closed enhancement (fixed)
XML-RPC returns only full-size URL for featured image
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.4 |
| Component: | XML-RPC | Version: | 3.4 |
| Severity: | normal | Keywords: | |
| Cc: | markoheijnen, maxcutler |
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)
comment:3
markoheijnen — 13 months 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.
- 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.
comment:5
markoheijnen — 13 months ago
That does make sense to me.
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.
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.
I think we can drop the extra underscore from the xmlrpc__prepare_media_item filter.
Refreshed patch after comments in IRC:
- Replaced get_post_meta calls with get_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.
comment:10
ryan — 13 months ago
- Owner set to ryan
- Resolution set to fixed
- Status changed from new to closed
In [20608]:
comment:11
ryan — 13 months 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.
comment:12
ryan — 13 months ago
We can either always load post-thumbnail-template.php or move get_post_thumbnail_id() and perhaps has_post_thumbnail() to post.php.
comment:13
markoheijnen — 13 months 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
comment:14
ryan — 13 months 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.
comment:15
ryan — 13 months ago
comment:16
markjaquith — 13 months ago
post-thumbnail-template.php is so tiny... there honestly can't be any benefit to having it loaded conditionally. It's five function definitions.
comment:17
nacin — 13 months ago
- Resolution set to fixed
- Status changed from reopened to closed
In [20610]:

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'.