Created
July 3, 2011 17:52
-
-
Save siygle/1062418 to your computer and use it in GitHub Desktop.
WordPress XMLRPC sample
This file contains 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
<?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