There are many ways to publish a WordPress blog post. You can publish from the WordPress admin interface, you can publish via email and also you can publish it via XML-RPC. So what is XML-RPC? XML-RPC is a remote procedure call (RPC) protocol which uses XML to encode its calls and HTTP as a transport mechanism. Which means we can call the WordPress procedure remotely. And this will make WordPress easily integrate with other systems.
To enable publish via XML-RPC in WordPress follow these steps:
- Log in to your WordPress admin
- Go to Settings > Writing > Remote Publishing
- Enable the “Enable the WordPress, Movable Type, MetaWeblog and Blogger XML-RPC publishing protocols” checkbox.
To try it you can use this code below:
function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8') {
$title = htmlentities($title,ENT_NOQUOTES,$encoding);
$keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding);
$content = array(
'title'=>$title,
'description'=>$body,
'mt_allow_comments'=>0, // 1 to allow comments
'mt_allow_pings'=>0, // 1 to allow trackbacks
'post_type'=>'post',
'mt_keywords'=>$keywords,
'categories'=>array($category)
);
$params = array(0,$username,$password,$content,true);
$request = xmlrpc_encode_request('metaWeblog.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);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}
To test it:
$title="Lorem ipsum";
$body="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vestibulum pharetra mi quis rhoncus. Mauris lacinia neque id lacus lobortis a dictum augue molestie. Proin ut elit velit, in faucibus neque. Aliquam libero odio, bibendum non tempor eu, sodales vel felis.";
$rpcurl="http://your_wordpress_blog_url/xmlrpc.php";
$username="Wordpress admin username here";
$password="Wordpress admin password here";
$categories="category name here";
echo wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories,'');
With this XML-RPC it is possible for you to write articles offline and then publish them with XML-RPC. Here are some good tools for that:
- Windows Live Writer (Windows Only)
- BlogJet (Windows Only)
- Blogo (Mac Only)
- MarsEdit (Mac Only)
- BloGTK (Linux Only)
- Scribefire (Firefox Add-on / All platform)
- Flock (Web Browser / All platform)
