WordPress 3.1 and XML-RPC
Every time I look through the beta of WordPress 3.1, I find something new. Today I found the WP_HTTP_IXR_Client. The IXR_Client was there in previous versions, but it didn’t use the WordPress HTTP API, and so it rarely worked for me. This wrapper/rework of it works like a charm. Some quick examples:
Testing the client to see if it can talk to another blog:
$client = new WP_HTTP_IXR_Client('http://example.com/xmlrpc.php'); $client->query('demo.sayHello'); echo $client->getResponse();
That will print “Hello!” if it succeeded.
Testing something with parameters, like adding two numbers:
$client = new WP_HTTP_IXR_Client('http://example.com/xmlrpc.php'); $client->query('demo.addTwoNumbers', 4, 5); echo $client->getResponse();
That will produce an output of 9… Okay, let’s do something meaningful.
$client = new WP_HTTP_IXR_Client('http://example.com/xmlrpc.php'); $client->query('wp.getOptions', 0, 'username', 'password', 'software_version'); $response = $client->getResponse(); echo $response['software_version']['value'];
It returns what version of WordPress I’m running on that test site. In this case, that would be 3.1-beta2-17056.
Take a look through the class-wp-xmlrpc-server.php file for the various things you can do. Maybe you can think of some handy ways to make your blogs talk to each other. 🙂
The original IXR code uses fsockopen, that doesn’t work for you? That said, converting to the WP HTTP API is worth while. Picking up the proxy support alone would be reason enough.
Sometimes it worked, sometimes it didn’t. Depended on the host. Lots of hosts block fsockopen.
Interesting, the Akismet plugin has been using fsockopen for years with a high degree of success. The biggest problem it had was lack of proxy support, which we got for free after moving to the WP HTTP API.
Yes, well, my sample of hosts is probably not representative of the whole. 🙂
The few I’ve had problems with fsockopen in the past have usually had curl installed, so the http api stuff worked fine for those cases, and I just used that instead.
Otto Im curious, would this enable something like i.e. a single signup across multiple blogs across multiple servers across the web, would be a neat way to bring the blogging communities together without having to rely on third parties, i.e. facebook or twitter connect as a great deal of sites don’t enable either for one reason or another.
Am I making sense?
Jay
It’s late and I’m tired from putting Christmas together, so forgive me if this is a stupid question.
Is this different than the XML-RPC in previous versions? I wrote some code a few months ago for a client that scraped their old non-wp-compatible site, converted the data as necessary, and posted their content, including featured images.
I’m probably missing the point of this all together
No, it’s not different to use to previous versions. The changes are related to the method how HTTP requests are done (now more flexible) and (which was not demonstrated by Otto in his post) that it is now more easy to extend the class. See http://core.trac.wordpress.org/ticket/10588 and http://core.trac.wordpress.org/changeset/16064 . The changes are AFAIK backwards compatible. They might not be if you included the library on your own for special purposes.
[…] se pustíte do propojení samostatných webů, tak doplňuji několik zajímavých odkazů (1, 2, 3), kde naleznete inspiraci… Příspěvek je starý 8 měsíců […]