I need to add custom methods to the Xml-Rpc file and have found the following:


// Custom plugins add_filter('xmlrpc_methods', 'custom_xmlrpc_methods');

function custom_xmlrpc_methods($methods) { $methods['myMethod'] = 'my_function'; return $methods; }

Questions:

  • Is it possible to have the callback function in another file and if yes then how do you do that in the code?
  • If I have lots of custom methods what is the best approach to handling this?

Thanks
Michael

3 Answers
3

If I have lots of custom methods what
is the best approach to handling this?

Instead of filtering xmlrpc_methods, you could extend the wp_xmlrpc_server class and set your class as default with the filter wp_xmlrpc_server_class.

// Webeo_XMLRPC.php
include_once(ABSPATH . WPINC . '/class-IXR.php');
include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php');

class Webeo_XMLRPC extends wp_xmlrpc_server {
    public function __construct() {
        parent::__construct();

        $methods = array(
            'webeo.getPost' => 'this:webeo_getPost',
            'webeo.getPosts' => 'this:webeo_getPosts'
        );

        $this->methods = array_merge($this->methods, $methods);
    }

    public static function webeo_getName() {
        return __CLASS__;
    }

    public function sayHello($args) {
        return 'Hello Commander!';
    }

    public function webeo_getPost($args) {
        // do the magic
    }

    public function webeo_getPosts($args) {
        // do the magic
    }
}

add_filter('wp_xmlrpc_server_class', array('Webeo_XMLRPC', 'webeo_getName'));

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *