2
votes

Ok so I currently have code working and I need to create a wordpress plugin with it.

Currently my code includes XMLRPC 2.2.2 and looks like the below...

   include("xmlrpc-2.2.2/lib/xmlrpc.inc");

   $sock = new xmlrpc_client($server_url.'common');
   $msg = new xmlrpcmsg('login');
   $msg->addParam(new xmlrpcval($dbname, "string"));
   $msg->addParam(new xmlrpcval($user, "string"));
   $msg->addParam(new xmlrpcval($password, "string"));
   $resp =  $sock->send($msg);

I want to utilize the HTTP API so that I don't rely on the user having curl for example...

My question is can I utilise this? Do i have to just edit the current xmlrpc library to use wordpress HTTP API or has this already been done?

Look forward to your reponses!!

1

1 Answers

1
votes

WordPress includes a XML-RPC class (IXR), it's a matter of

include 'wp-includes/class-IXR.php'; // better with:  ABSPATH . WPINC . '/class-IXR.php';
$client = new IXR_Client( 'http://example.com/xmlrpc.php' );
if( !$client->query( 'demo.sayHello', array() ) )
    echo $client->getErrorMessage();
else
    echo $client->getResponse();

And for authenticated requests:

$query_args = array(  
    'post_status' => 'publish',
    'post_type'   => 'post',
    'number'      => 3
);
$args = array(
    '', // blog_id
    'username',
    'password',
    $query_args
);        
$result = $client->query( 'wp.getPosts', $args );