Skip to content

Instantly share code, notes, and snippets.

@mgebundy
Last active May 4, 2016 04:08
Show Gist options
  • Save mgebundy/3830383 to your computer and use it in GitHub Desktop.
Save mgebundy/3830383 to your computer and use it in GitHub Desktop.
Building custom XML-RPC methods in WordPress
<?php
// Include the XML-RPC files
include_once(ABSPATH . WPINC . '/class-IXR.php');
include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php');
class my_xmlrpc extends wp_xmlrpc_server {
function __construct() {
// This filter will add the new methods we're building
add_filter('xmlrpc_methods', array($this, 'my_xmlrpc_methods'));
parent::__construct();
}
function my_xmlrpc_methods($methods) {
$methods += array(
// Methods here.
'my.login_verify' => 'this:my_login_verify'
);
return $methods;
}
/*
* The Methods
*/
function my_login_verify($args) {
// ALWAYS escape $args before using them!
$this->escape($args);
$username = $args[0];
$password = $args[1];
if ( !$user = $this->login($username, $password) )
return $this->error;
return true;
}
}
// Make this the class we use!
add_filter('wp_xmlrpc_server_class', create_function('', 'return "my_xmlrpc";'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment