Custom APIs are essential for adding web application specific behaviors, which goes beyond the generic blogging functionality. We need the implementation for both the server and client to create a custom API. Here, we are going to build an API function that outputs the list of developers in a portfolio application. As usual, we are going to get started by creating another plugin folder named wpwa-xml-rpc-api
with the main file named class-wpwa-xml-rpc-api.php
.
Let's look at the initial code to build the API server:
class WPWA_XML_RPC_API { public function __construct() { add_filter('xmlrpc_methods', array($this, 'xml_rpc_api')); } public function xml_rpc_api($methods) { $methods['wpwa.getDevelopers'] = array($this, 'developers_list'); return $methods; } } new WPWA_XML_RPC_API();
First, we use the plugin constructor to add the WordPress filter named xmlrpc_methods
, which allows us to customize the API functions assigned to WordPress. The preceding filter...