Created
October 13, 2012 20:27
-
-
Save achilles283/3886029 to your computer and use it in GitHub Desktop.
Publish a post to WordPress using cURL/XMLRPC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.catswhocode.com/blog/10-awesome-things-to-do-with-curl | |
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.catswhocode.com/blog/10-awesome-things-to-do-with-curl | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment