See the Snippets! You can get productive in minutes or waste days and debug huge amounts of free and crappy code to get to 5% of elWpAPI's functionality.

WordPress Remote Control

WordPress XMLRPC Remote Publishing API (and beyond) by Easy-to-use PHP Objects

••• Hey there! Click here to buy, download or update the WpAPI library ONLY after you read the #3 Testimonials •••

Advanced Snippets

Unlike the Basic Snippets, these require the rFC-rSQL plugin which is provided with elWPAPI to be installed in your /wp-content/mu-plugins folder, or installed in your /wp-content/plugins folder and enabled. The plugin will grant access to Remote Function Calls (rFC) and Remote SQL (rSQL) Queries, hence giving you virtually unlimited control over your WordPress blog.

1 | Mastering rSQL

<?php
// Get the blog $table_prefix
$prefix = (string)$wp->remoteQuery("get_prefix", false);
// Get the reachable schemas
$schemas = (array)$wp->remoteQuery("get_schemas", false);
// Get the reachable schemas and tables
$schemas_tables = (array)$wp->remoteQuery("get_schemas", true);
// Get the current schema
$schema = (string)$wp->remoteQuery("get_schema");
// Get the Wordpress tables to further work with them
$tables = (object)$wp->remoteQuery("get_tables");
// Get all the tables starting with the $table_prefix to further work with them
$prefixed_tables = (object)$wp->remoteQuery("blog_tables");
// Get all blogs prefixes in current schema by matching prefixes on term_taxonomy tables
$blogs = (array)$wp->remoteQuery("get_blogs");
// Get all the posts with a swift query
$posts = (object)$wp->remoteQuery("get_results", "SELECT * FROM {$tables->posts};");
// Get the post count
$count = (int)$wp->remoteQuery("get_var", "SELECT COUNT(*) FROM {$tables->posts};");
// Get the post count
$postIDs = (int)$wp->remoteQuery("get_col", "SELECT `ID` FROM {$tables->posts};");
// Get latest post
$post = (object)$wp->remoteQuery("get_row", "SELECT * FROM {$tables->posts} ORDER BY `ID` DESC LIMIT 1;");
?>

2 | Mastering rFC

rFC means Remote Function Call and allows you to call any WordPress function from your elWPAPI script. This gives you a lot more versatility in remote blogging.

<?php
// Change page template; any call to a missing $wp method is directed to 5ub.rFC
$success = $wp->update_post_meta($pageID, '_wp_page_template', basename($template_file));
// The above is equivalent to the below
$success = $wp->doRequestUP('5ub.rFC', 'update_post_meta', $pageID, '_wp_page_template', basename($template_file));
// The aboves are equivalent to the below
$success = $wp->remoteCall('update_post_meta', $pageID, '_wp_page_template', basename($template_file));
?>

3 | Using Eval()

eval() is supported by rFC thus giving you a lot more power in creating and running more advanced scripts, remotely, on your blog. XMLRPC is designed for single function calls, eval() can take raw PHP and evaluate it. Not a feature for beginners but once mastered, you can do anything.

<?php
// This will return the $table_prefix.
// Can you see potential of running advanced code in one hit?

$wp->remoteEval('global $table_prefix; return $table_prefix;');
// You can even use nowdoc strings in PHP 5.3+
$wp->remoteEval(<<<'PHP'
     global $table_prefix;
     return $table_prefix;

PHP
);
?>

4 | Using EvalWrap()

eval_wrap() is supported by rFC thus giving you a lot more power in creating and running more advanced scripts, remotely, on your blog. XMLRPC is designed for single function calls, eval() can take raw PHP and evaluate it. Not a feature for beginners but once mastered, you can do anything.

The only difference between eval() and eval_wrap() is that while eval() evaluates the code inline and does not accept parameters, eval_wrap() evaluates the code in an anonymous function created with create_function() and accepts arguments which can be accessed using func_get_arg(). I can do anything with this function and the new elWpAPIfud shows what it can do (like upload/download Files).

<?php
// This will return the $table_prefix.
// Can you see potential of running advanced code in one hit?

$wp->remoteEvalWrap('return func_get_args();', 'arg1', 'arg2');
// You can even use nowdoc strings in PHP 5.3+
$wp->remoteEval(<<<'PHP'
     return func_get_args();
PHP
, 'arg1', 'arg2');
?>

5 | Compact() $GLOBALs

It's also a problem getting $GLOBAL values with XMLRPC without using eval(). So, compact_globals() does what compact() does, but with GLOBAL variables.

<?php
// Get the WordPress version using the GLOBAL variable
$wp->compact_globals('wp_version'); // [, ...]
// Accepts multiple arguments and returns an array

?>