Skip to content

Instantly share code, notes, and snippets.

@siygle
Created July 3, 2011 17:52
Show Gist options
  • Save siygle/1062418 to your computer and use it in GitHub Desktop.
Save siygle/1062418 to your computer and use it in GitHub Desktop.
WordPress XMLRPC sample
<?php
$username = '';
$password = '';
$blogid = ''; // Can get using wp.getUsersBlogs
$target_host = '';
$xmlrpc_method = '';
function get_response($url, $context){
if(!function_exists('curl_init')){
die('Curl PHP not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $context);
$response = curl_exec($ch);
return $response;
}
$request = xmlrpc_encode_request($xmlrpc_method, array($username,$password));
$xml = get_response($target_host, $request);
$response = xmlrpc_decode($xml);
if($response && xmlrpc_is_fault($response)){
echo 'error';
} else {
print_r($response);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment