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.
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.
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.
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
especially when you try to set the dateCreated etc you need to convert to iso, it's much easier to use a lib