Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: OpenSocial for BuddyPress


Boone Gorges
Keymaster

@boonebgorges

Hey Carl – Here are a couple considerations.

– WordPress (which BP runs on top of) already has support for XML-RPC. Here’s the spec: https://codex.wordpress.org/XML-RPC_wp Of course, the details of this spec are not much good for BuddyPress, since for the most part, BuddyPress data objects are different from WP data objects. But the gateways are already there for working with XML-RPC.

– That said, the kind of system-to-system talking that would be appropriate for BP would be much better suited to the simplicity of a REST gateway (as opposed to the generally one-to-one, client-to-server relationship that WP’s XML-RPC support was built for – eg the use case of native Android apps communicating with a WP installation).

– Neither WP nor BP has anything built in for REST support, so you’ll be starting with a clean slate (that is both good news and bad news!). There have been a few add-ons that might be good places to start. The one I’ve used in the past is called WP-RESTful https://wordpress.org/extend/plugins/wp-restful/. It’s a nice plugin, but it also has a huge amount of overhead, in particular with a full implementation of oAuth.

– In the very simplest terms, the very easiest way to set up a REST endpoint in WP is to intercept a certain kind of URL query and interpret the POST data. Here is about the most stripped down API possible:
`function bbg_api_listener() {
global $wp;

if ( $r = $wp->request ) {
$ra = explode( ‘/’, $r );
if ( $ra[0] == ‘restserver’ ) {
// Do some stuff with the $_POST
die();
}
}
}
add_action( ‘wp’, ‘bbg_api_listener’, 1 ); // Ensure that the request is parsed before any WP front-end stuff, but after the core of WP is loaded`

In this case, I am assuming that requests will go to example.com/restserver. From there it’s a matter of unpacking the POST action, etc.

– As for outgoing requests, WP has a pretty nice built-in HTTP library called WP_Http. Here is a nice tutorial: http://planetozh.com/blog/2009/08/how-to-make-http-requests-with-wordpress/ It’s a wrapper for cURL with some graceful fallbacks.

– For something to go into the core of BuddyPress it needs to be really flexible, especially in terms of authorization (this is part of the problem with WP-RESTful and its reliance on oAuth). Keep that separation in mind when you’re crafting something.

Can’t wait to see what you come up with. As you know, I’m really interested in this project and will be excited to play along.

Skip to toolbar