XMLRPC- Hello World- demo.sayHello

With WordPress XMLRPC, you can blog from your desktop client. WordPress XMLRPC provides a series of methods to perform various operations which you normally do from your WordPress website. To start working with wordpress XMLRPC, let’s take a  simple “Hello World!” program


/*The URL of the blog*/
$BLOGURL = "http://localhost/wordpress";

function get_response($URL, $context) {
    if(!function_exists('curl_init')) {
    die ("Curl PHP package not installedn");

    /*Initializing CURL*/
    $curlHandle = curl_init();

    /*The URL to be downloaded is set*/
    curl_setopt($curlHandle, CURLOPT_URL, $URL);
    curl_setopt($curlHandle, CURLOPT_HEADER, false);
    curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);

    /*Now execute the CURL, download the URL specified*/
    $response = curl_exec($curlHandle);
    return $response;

/*Creating the demo.sayHello request
function demo_sayHello() {
   global $BLOGURL;
   $request = xmlrpc_encode_request("demo.sayHello", "");

    /*Making the request to wordpress XMLRPC of your blog*/
    $xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
    $response = xmlrpc_decode($xmlresponse);

    /*Printing the response on to the console*/

echo "n";

On executing this simple program, you will get a simple “Hello World!” message as the response. This is a simple method which doesn’t take any arguments. All you have to do is to make a call to “demo.sayHello”

$ php demo.sayHello.php

<?xml version="1.0"?>


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s