WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 2 years ago

Last modified 2 years ago

#15098 closed enhancement (fixed)

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

Reported by: rvavruch Owned by: 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 4 years ago.
Return an id when performing a metaWeblog.newMediaObject
featured_image_xmlrpc.patch (2.7 KB) - added by cfinke 3 years ago.
Adds support for featured_image field in XML-RPC.
15098.patch (691 bytes) - added by maxcutler 2 years ago.
Return ID with wp.uploadFile/metaWeblog.newMediaObject

Download all attachments as: .zip

Change History (24)

rvavruch4 years ago

Return an id when performing a metaWeblog.newMediaObject

comment:1 nacin4 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.

comment:2 rvavruch4 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.

comment:3 josephscott4 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.

comment:4 follow-up: Seanmcn3 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!

comment:5 in reply to: ↑ 4 rvavruch3 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

comment:6 westi3 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.

cfinke3 years ago

Adds support for featured_image field in XML-RPC.

comment:7 cfinke3 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.

comment:8 follow-up: koke3 years ago

  • Cc jbernal@… added
  • Keywords mobile added

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

comment:9 markoheijnen3 years ago

  • Cc marko@… added

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

comment:10 in reply to: ↑ 8 mrroundhill3 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.

comment:11 trusktr2 years ago

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

comment:12 isaackeyet2 years ago

  • Cc isaackeyet added

comment:13 screenwavemedia2 years ago

  • Cc screenwavemedia added

comment:14 markoheijnen2 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.

comment:15 koke2 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

comment:16 maxcutler2 years ago

  • Cc max@… added

maxcutler2 years ago

Return ID with wp.uploadFile/metaWeblog.newMediaObject

comment:17 maxcutler2 years ago

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

comment:18 westi2 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

comment:19 maxcutler2 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.

comment:20 ocean902 years ago

  • Milestone changed from Future Release to 3.4

comment:21 trusktr2 years ago

Sweet!

Note: See TracTickets for help on using tickets.