Extending WordPress XML-RPC to include custom post types and taxonomies

I am trying to insert a post with a custom post type, which I also want to attach custom taxonomies. Most of the patches available are outdated any only apply to “xmlrpc.php”. Now the file in wordpress that controls the function is “class-wp-xmlrpc-server.php”. Could someone give me advice on how to dissect the file? I would prefer to add a filter to my theme file rather than overwriting WordPress core files.

Related posts

Leave a Reply

1 comment

  1. I realize that this is an old topic, but I’ve been wondering the same thing in the last couple of weeks and totally rewrote some of that file to work with what I needed it to do. For my implementation, I have a custom post type called ‘blog’, with custom taxonomies called ‘blog_categories’ and ‘blog_tags’. A little redundant, yes, but it was an experiment sort of.

    If you take a look at class-wp-xmlrpc-server.php, you’ll notice that it’s a bit messy (depending on the version of WP you are using it may be better or worse). The easiest way I found to go about it without breaking anything was to go ahead and change the taxonomy functions to the generic ones rather than the category and post specific ones. That involves finding all of the instances of wp_get_post_categories and wp_get_post_tags and replacing them with the more generic wp_get_object_terms, and replacing get_categories with get_terms. Once this works using categories and tags as the taxonomy, you can do one of two things:

    1. In my situation, XML-RPC just needed to work like default, except change post to blog, categories to blog_categories, etc. I just replaced the literals and my new XML-RPC allowed me to use Live Writer like normal, but it would use my custom post type and taxonomies.
    2. If you need functions available to work with multiple post types and taxonomies, you’ll need to dig a little deeper and rewrite the functions (ideally, rewrite them to work with 0-n taxonomies and any post type). Consider backwards compatibility if you want to use existing software like Live Writer. Also consider capabilities – if you have custom roles for your custom post types, then you should consider replacing the capability checks with something like: user_can('edit'_.$post_type, $postid).

    Sadly, WordPress is victim to the 1 post type, 2 post types (pages), n post types (custom) evolutionary model, and XML-RPC hasn’t gotten as much love as the rest of the system. There are some filter/action hooks in there you could investigate, but I think you’ll have an easier time just modifying the core file. This means your modifications will be overwritten on core updates though!

    Hope this helps a little for you and anyone else looking to do the same thing!