WordPress API XML-RPC – New Easy to Use PHP Class

Here’s the story. I’ve been working on a tool which automatically creates posts inside of WordPress. And in short it’s been difficult to find good documentation on the API and I’ve not been very familiar with XML-RPC. Well today everything changes.

I’ve created a PHP class that you can use to create posts in WordPress using the their new API released in WordPress 3.4. It’s called wpclass and is hosted on GitHub.
This PHP class allows you to use wp.newPost to create posts and supports most of the functionality. Currently I’ve only done a function to create and publish posts, but this class is easily expandable so we can add functions as needed.

Previously I was using the metaWeblog.newPost which had some bugs especially related to datetime values. I’ve fixed all that in this PHP class, by default it will use the current date when creating posts, or you can use the PHP date function to define the date of this post.

So have fun and enjoy your posting via API!

5 Replies to “WordPress API XML-RPC – New Easy to Use PHP Class”

  1. Thank you for this useful code! 🙂 Do you have any idea how to convert the XML response to a PHP array? I keep getting an XML response and unable to parse it to a php array…

    $response = curl_exec($this->ch);
    $result = xmlrpc_decode($response);

    I see that xmlrpc_decode() is used, but nonetheless I get the response as an XML and unable to use it further in PHP.

  2. Wow! I don’t think many beginner level developers fully “get” how valuable this is. Thanks!!

  3. Suggestion, but I will post it here after I do it. For beginners (like me) it would be invaluable to have lots of // comment out instructions on how to edit the data. It’s great that there is $this variable that directs users where to edit, but for instance, I don’t know what to put in the $this->ch areas. I have no idea what the value of “ch” should be, and it took awhile figure out how to find the $blogid, which in my case was just the admin user id of “1” found in the Dashboard=>Users area. The endpoint is also a mystery to beginners being “some-site.com/xmlrpc.php”.

    Once I figure it all out I’ll post the same script with the comments OK.

Leave a Reply

Your email address will not be published. Required fields are marked *