Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#15405 closed task (blessed) (fixed)

Extend Post Format support to the XML-RPC API

Reported by: ericmann's profile ericmann Owned by: ericmann's profile ericmann
Milestone: 3.1 Priority: normal
Severity: normal Version: 3.1
Component: XML-RPC Keywords: has-patch, dev-reviewed
Focuses: Cc:

Description

Currently, there's no way to specify a post format while creating a post via XML-RPC. There's also no way to retrieve the post format for a particular post via XML-RPC. This support must be added.

Related: #14746

Attachments (4)

XMLRPCpostformats.diff (3.5 KB) - added by ericmann 14 years ago.
Adds post format support to XML-RPC methods.
XMLRPCpostformats.2.diff (3.5 KB) - added by ericmann 14 years ago.
Fixed an error with the output of wp.getPostFormats
XMLRPCpostformats.3.diff (3.5 KB) - added by ericmann 14 years ago.
Allows for "default" to be used to set a post format of "default." Works in addition to the default value of "0."
post-format-rpc.diff (4.6 KB) - added by josephscott 14 years ago.

Download all attachments as: .zip

Change History (16)

#1 @westi
14 years ago

  • Cc westi added
  • Milestone changed from Awaiting Review to 3.1

#2 @josephscott
14 years ago

  • Cc josephscott added

#3 follow-up: @josephscott
14 years ago

Adding this to the existing metaWeblog.newPost|editPost|getPost is one option. In addition a wp.getPostFormats method would be handy so that clients can get a list of valid format names.

#4 in reply to: ↑ 3 @ericmann
14 years ago

Replying to josephscott:

In addition a wp.getPostFormats method would be handy so that clients can get a list of valid format names.

Considering the list of valid post formats is going to be fixed in 3.1, I don't think this is too large of a concern. But amending the existing newPost/editPost/getPost methods would be a good idea and is, indeed, my plan :-)

#5 @westi
14 years ago

wp.getPostFormats we should add this even though we intend to hard code them.

The clients can be forward compatible with a changing list.

#6 @ericmann
14 years ago

  • Keywords has-patch added; needs-patch removed

The above patch adds the wp_post_format as an input parameter for the post struct in the following methods:

  • metaWeblog.newPost
  • metaWeblog.editPost

If wp_post_format is not defined in a create/edit post request it's ignored.

The patch adds the same as a return parameter for the post struct in the following methods:

  • metaWeblog.getPost
  • metaWeblog.getRecentPosts

Finally, this patch adds a new method for retrieving a list of supported post formats (slug and name): wp.getPostFormats. This new method follows the blog_ID, username, password request format of existing method calls (though blog_ID doesn't seem to be used anywhere, it's added here for the same of consistency).

@ericmann
14 years ago

Adds post format support to XML-RPC methods.

#7 @westi
14 years ago

  • Type changed from enhancement to task (blessed)

We need this to complete the Post Formats feature

@ericmann
14 years ago

Fixed an error with the output of wp.getPostFormats

#8 @josephscott
14 years ago

I ran through a few tests with this new patch.

The response from wp.getPostFormats has one odd piece:

Array
(
    [0] => Default
    [aside] => Aside
    [chat] => Chat
    [gallery] => Gallery
    [link] => Link
    [image] => Image
    [quote] => Quote
    [status] => Status
    [video] => Video
)

Seems like that first value should be something like '[default] => Default' instead.

For metaWeblog.getPost, if a post has the 'Default' format the wp_post_format value is empty in the response. This might be related to the zero item above. When the format was not default wp_post_format contained the related string value for that format.

The metaWeblog.newPost method also had problems with setting the wp_post_format to 'default'. If I set it to 'aside' that worked fine, but setting it to 'default' ended up with some unknown format value.

And metaWeblog.editPost has the same problem as .newPost. Setting wp_post_format to 'aside' works fine, but setting it to 'default' left the format value of the post in some sort of limbo.

#9 @ericmann
14 years ago

Taking a look at the actual post format definitions, it's hard-coded as [0] => _x('Default', 'Post format') ... so I'm going to leave the response from wp.getPostFormats as-is to reflect that.

The metaWeblog.getPost method is behaving as it should. If the wp_post_format value is empty, then it's the default format - if the post format is not explicitly set, it is empty and "default" is assumed.

However, I will make it so that metaWeblog.newPost and metaWeblog.editPost will accept "default" as an acceptable value.

@ericmann
14 years ago

Allows for "default" to be used to set a post format of "default." Works in addition to the default value of "0."

#10 @josephscott
14 years ago

I chatted with MarkJ who committed the get_post_format_strings() function with the zero index for default. He agreed that 'default' would be better for that and committed the change - r16477

I've uploaded an updated diff that did a couple of things:

  • made a few adjustments to the patch to be more in line with WP coding style. The XML-RPC code has done a poor job of keeping with that style, but may as well start here :-)
  • tightened up the wp_getPostFormats() function just a bit
  • added validation of the wp_post_format field for methods that use it for updating the post format. If we get an invalid post format return an XML-RPC error indicating the problem
  • for methods that include wp_post_format in the response, set the value to 'default' if the post format is empty

This patch passed my run of tests.

#11 @westi
14 years ago

  • Keywords dev-reviewed added

This looks great.

#12 @josephscott
14 years ago

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

(In [16484]) Expose post format details in XML-RPC:

  • New method: wp.getPostFormats
  • New field in methods dealing with posts: wp_post_format

props ericmann, fixes #15405

Note: See TracTickets for help on using tickets.