2

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 Answer 1

1

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 );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.