WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#16476 closed enhancement (duplicate)

Custom post types support in XML-RPC

Reported by: tillkruess Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: XML-RPC Keywords:
Focuses: Cc:

Description

The function mw_newPost (metaWeblog.newPost) does not support custom post types, only post and page are supported.

Publishing custom post types via rpc would be neat.

Attachments (1)

class-wp-xmlrpc-server.php.diff (13.4 KB) - added by rofflox 3 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 axwax3 years ago

+1 from me.
I agree it'd be great if XMLRPC wasn't limited to posts and pages.

comment:2 rofflox3 years ago

I've already played around with this. In my opinion, the whole wp-xmlrpc-server class should be overhauled.

For example:

  1. Create a generic wp_getPost / wp_newPost / wp_deletePost / wp_editPost
  2. The output of the functions should be more or less the same as in the default functions. E.g. title => post_title, postid => ID etc.
  3. For backwards compatibility:
    1. Create all sub functions e.g. mw_getPost with link to the generic wp_getPost
    2. Add an optional second parameter "mode" to format the output based on the calling function. E.g. mode = mw_getPost will format the output of the result array in a different way.
  4. Take an associative array instead of a numeric one as argument, so we could seamless add additional features in the future. Thats already WP standard.
  5. For custom post types, we have to check for the registered capbilities. Unfortunaltey, they aren't mapped by default. This should also be added to the register_posttype function. e.g.
if (! current_user_can('edit_' . $args->post_type, $args->post_id)) {
    return new IXR_Error(401, __('Sorry, you cannot edit the post type _' . $args->post_type . '_.'));
}

I've added a working example for wp_getPost, wp_getPosts and wp_getPage in the diff. Maybe someone could check if this is a good approach and give feedback.

Version 1, edited 3 years ago by rofflox (previous) (next) (diff)

comment:3 hakre3 years ago

Can you provide a patch w/o deprecating for the moment? It's not that I won't like the idea but to keep things simple and I think deprecation needs some decision first.

comment:4 ptahdunbar3 years ago

  • Cc trac@… added

comment:5 josephscott3 years ago

I like having custom post type support in XML-RPC, but I don't think this is the way forward on it. I think this is a good time to consider some new methods that will work on any post type (custom and built in).

comment:6 raamdev3 years ago

  • Cc raam@… added

comment:8 SergeyBiryukov2 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.