From 6c7cc5de0d4b3d0c552e363924ae2b6c45b89ecc Mon Sep 17 00:00:00 2001 From: Alexey Stoletniy Date: Wed, 22 Feb 2017 11:19:35 +0300 Subject: [PATCH] Implement support for additional endpoints in Free API [PREMIUM-4] --- lib/API/API.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/API/API.php b/lib/API/API.php index e466bd9c38..ef7f1d1cdf 100644 --- a/lib/API/API.php +++ b/lib/API/API.php @@ -9,9 +9,14 @@ class API { private $_method; private $_token; + private $_endpoint_namespaces = array(); private $_endpoint_class; private $_data = array(); + function __construct() { + $this->addEndpointNamespace(__NAMESPACE__ . "\\Endpoints"); + } + function init() { // Admin Security token add_action( @@ -33,6 +38,8 @@ class API { } function setupAjax() { + do_action('mailpoet_api_setup', array($this)); + $this->getRequestData(); if($this->checkToken() === false) { @@ -71,9 +78,12 @@ class API { ); $error_response->send(); } else { - $this->_endpoint_class = ( - __NAMESPACE__."\\Endpoints\\".ucfirst($this->_endpoint) - ); + foreach($this->_endpoint_namespaces as $namespace) { + $class_name = $namespace . "\\" . ucfirst($this->_endpoint); + if(class_exists($class_name)) { + $this->_endpoint_class = $class_name; + } + } $this->_data = isset($_POST['data']) ? stripslashes_deep($_POST['data']) @@ -149,4 +159,8 @@ class API { $global .= ''; echo $global; } + + function addEndpointNamespace($namespace) { + $this->_endpoint_namespaces[] = $namespace; + } }