views:

519

answers:

3

Hi guys,

I want to consume wordpress XMLRPC API for my latest experiment. Do you know what is the simplest library to do this? PHP4 compatibility is not important as it's obsolete anyway.

+1  A: 

I won't suggest a library. I'll give you a simple curl example for a new wordpress post. To use it on your own, you may want to create a class for this stuff that there is no need to have user/pass as function parameters.

function wpPostXMLRPC($title, $body, $rpcurl, 
                      $username, $password, $categories=array(1))
{
   $categories = implode(",", $categories);
   $XML = "<title>$title</title>".
          "<category>$categories</category>".
   $body = "Example body text - hallo wordpress";

   $params = array('','',$username,$password,$XML,1);
   $request = xmlrpc_encode_request('blogger.newPost',$params);
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
   curl_setopt($ch, CURLOPT_URL, $rpcurl);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_TIMEOUT, 1);
   curl_exec($ch);
   curl_close($ch);
}

The question is for what reason do you need a library if it is soooo easy...

The PEAR XML-RPC package may be interessting for you.

tuergeist
The reason why I want to use library is, so that I don't have to convert wordpress's XMLRPC result back to array all by myself. I want that library do the dirty stuff!
silent
+2  A: 

Actually, I got the answer using wordpress's own XMLRPC processor which is based on incutio's XMLRPC library. The file is in /wp-includes/class-IXR.php

silent
A: 

especially when you try to set the dateCreated etc you need to convert to iso, it's much easier to use a lib

att