Make WordPress Core

Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#15098 closed enhancement (fixed)

Can't add post with featured image using only XML-RPC

Reported by: rvavruch's profile rvavruch Owned by: rvavruch's profile rvavruch
Milestone: 3.4 Priority: normal
Severity: normal Version:
Component: XML-RPC Keywords: needs-patch mobile
Focuses: Cc:

Description

AFAIK it is not possible to add a new post with a featured image using only XML-RPC. This is because the way to add a featured image with XML-RPC requires the wp_posts.id of the image to be used.

I have attached a patch based on trunk rev. 15775 which returns that id when performing a metaWeblog.newMediaObject. This id can then be used in the custom_fields of a metaWeblog.newPost to set the featured image (or _thumbnail_id).

Attachments (3)

xmlrpc_patch.diff (820 bytes) - added by rvavruch 14 years ago.
Return an id when performing a metaWeblog.newMediaObject
featured_image_xmlrpc.patch (2.7 KB) - added by cfinke 13 years ago.
Adds support for featured_image field in XML-RPC.
15098.patch (691 bytes) - added by maxcutler 13 years ago.
Return ID with wp.uploadFile/metaWeblog.newMediaObject

Download all attachments as: .zip

Change History (24)

@rvavruch
14 years ago

Return an id when performing a metaWeblog.newMediaObject

#1 @nacin
14 years ago

_thumbnail_id is ideally internal. We shouldn't be expecting that to get passed around via XML-RPC to attach an image as a featured image.

#2 @rvavruch
14 years ago

At the moment - unless I missed something - the only way to attach an image as a featured image through XML-RPC is by setting _thumbnail_id in the metaWeblog.newPost custom_fields parameter.

Should we open a new ticket to add a better method of setting the featured image?

It would be ideal if we could add the data required by "metaWeblog.newMediaObject" to a metaWeblog.newPost setting that as the featured image. That may break some standard though.

As it currently stands, the patch uploaded is a tiny change which solves the issue with the system as is.

#3 @josephscott
14 years ago

At a conceptual level I think this does much better being part of the metaWeblog.(new|edit)Post. Adding support for a 'featured_image' field would be enough. The post_id isn't a problem, check out the mw_newPost function, you'll see that we wait until after the new post has been created to process sticky options since those also require a valid post_id.

The data could then be exposed via the 'featured_image' field from metaWeblog.getPost.

#4 follow-up: @Seanmcn
14 years ago

Strange, I don't seem to have wp-includes/class.wp-xmlrpc-server.php ..

Using Wordpres 3.0.4

But I'd really like this feature, trying to pull in posts daily with XML and trying to set a featured image is a giant pain!

#5 in reply to: ↑ 4 @rvavruch
14 years ago

  • Cc rvavruch added
  • Owner set to rvavruch
  • Status changed from new to assigned

Replying to Seanmcn:

Strange, I don't seem to have wp-includes/class.wp-xmlrpc-server.php ..

Using Wordpres 3.0.4

But I'd really like this feature, trying to pull in posts daily with XML and trying to set a featured image is a giant pain!

The file was moved in the latest (unreleased) version. The change still works for older released versions if you want to backport it, but you have to manually add it to the file "xmlrpc.php", on this line:

http://core.trac.wordpress.org/browser/tags/3.0.1/xmlrpc.php#L2832

#6 @westi
14 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

This should be promoted to a proper parameter for the api call as suggested above.

@cfinke
13 years ago

Adds support for featured_image field in XML-RPC.

#7 @cfinke
13 years ago

  • Cc cfinke added

I'd really like to be able to support featured images in ScribeFire, so I've added a patch that exposes featured images in the following ways:

  • It includes the ID of each media object in the return value of getMediaLibrary.
  • It accepts a featured_image field as input to mw_newPost and mw_editPost; the value is a media object ID.
  • It returns as part of getRecentPosts a featured_image struct containing the ID and url values for the image.
  • It removes the featured image if featured_image is not set as part of the request to mw_editPost. (This might not be optimal, since the moment that this change goes live, any posts edited via the API will lose their featured images unless the clients released a pre-emptive update to support this API change.)

This should be enough for clients to get/set/remove featured images; if you think it would be better to pass around URLs only, I can update the patch to reflect that.

#8 follow-up: @koke
13 years ago

  • Cc jbernal@… added
  • Keywords mobile added

Added mobile tag, this is one of the top feature requests for mobile apps

#9 @markoheijnen
13 years ago

  • Cc marko@… added

For setting the post thumbnail it probably would be better to use the core function set_post_thumbnail().

#10 in reply to: ↑ 8 @mrroundhill
13 years ago

  • Cc dan@… added

Replying to koke:

Added mobile tag, this is one of the top feature requests for mobile apps

+1, a lot of requests for this coming in for WPAndroid.

#11 @trusktr
13 years ago

I can't wait for featured images via the android app. :D

#12 @isaackeyet
13 years ago

  • Cc isaackeyet added

#13 @screenwavemedia
13 years ago

  • Cc screenwavemedia added

#14 @markoheijnen
13 years ago

Added a new patch at #18429 that also fixes this issue. I only return the id at this moment. I do wonder if the url should be returned.
If so then we also should do that with the new wp post methods.

#15 @koke
13 years ago

Maybe I'm missing something, but looking at the latest patch, metaWeblog.newMediaObject doesn't return an attachment id, so you can't really set new image as featured

#16 @maxcutler
13 years ago

  • Cc max@… added

@maxcutler
13 years ago

Return ID with wp.uploadFile/metaWeblog.newMediaObject

#17 @maxcutler
13 years ago

Addressed koke's concern by returning the attachment ID in wp.uploadFile and metaWeblog.newMediaObject. Test in [UT588].

#18 @westi
13 years ago

In [20305]:

XMLRPC: Add the object ID to the return data of wp.uploadFile/metaWeblog.newMediaObject so that it can be used in other api calls e.g. setting featured image see #15098 props maxcutler

#19 @maxcutler
13 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

This was fixed for 3.4, in [20305] and #18429.

New bugs or enhancements on new tickets.

#20 @ocean90
13 years ago

  • Milestone changed from Future Release to 3.4

#21 @trusktr
13 years ago

Sweet!

Note: See TracTickets for help on using tickets.