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
Instead of filtering
xmlrpc_methods
, you could extend thewp_xmlrpc_server
class and set your class as default with the filterwp_xmlrpc_server_class
.This doesn’t realyl have much to do with WordPress, just generic PHP and your personal preferences in coding.
As with any PHP code you can split it between files and load them with
include
.As for me (if you are not using classes) single file with all functions organized in some way (for example by purpose ot alphabet) will do.
If you are looking to use other existing WordPress functions that aren’t included in their XML-RPC, try using the plugin Extend XML-RPC API.
Otherwise, download that plugin and use the code as an example…it should be plenty for you to understand how to add your own plugins to the XML-RPC.