I'm working on an integration between an outside app (which needs to pull user names and some taxonomy data, and create new posts) and a WordPress site. I'm running the latest build of WP (4.0).
The XML-RPC documentation being as spare as it is, I'm hoping someone out there can just pastebin a recent (2014?) working example. Honestly, the google machine simply fails on this one.
Ideally, the code example would use the WP's bundled libraries (class-IXR.php, class-wp-http-ixr-client.php) rather than some outside XMLRPC library.
Here's what's NOT working (yet):
<?php
get_header();
include_once( ABSPATH . WPINC . '/class-IXR.php' );
include_once( ABSPATH . WPINC . '/class-wp-http-ixr-client.php' );
$client = new WP_HTTP_IXR_CLIENT( 'redactedSITEURL' );
$post = array(
'post_type' => 'post',
'post_status' => 'draft',
'post_title' => 'Test Post',
'post_content' => 'This is my test post',
'post_author' => 1
);
$data = xmlrpc_encode_request('wp.newPost', array('redactedURL.com', 'redactedUNAME', 'redactedPASSWORD', $post);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'redactedSITEURL.com/xmlrpc.php');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$exec = curl_exec($ch);
$response = xmlrpc_decode($exec);
curl_close($ch);
var_dump($response);
?>