WordPress XML-RPC

I wanted a stripped-down “mobile” version of the WP admin interface for posting, but I couldn’t find a suitable one. So while I thought about writing my own, I looked for ready made XML RPC solutions.

Indeed, as I expected, one function is all it takes.


function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories=array(1)){
	$categories = implode(",", $categories);
	$XML = "$title".
	"$categories".
	$body;
	$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);
}

I made a small HTML form and submitted it to this PHP function, and that’s it! 15 minutes worth of work.

Leave a Reply