Closes issue 480

This commit is contained in:
Jonathan Labreuille
2016-09-21 11:53:27 +02:00
parent 0ba48234de
commit 6091751a4b
14 changed files with 185 additions and 192 deletions

View File

@ -6,9 +6,6 @@ use \MailPoet\Util\Security;
if(!defined('ABSPATH')) exit;
class API {
function __construct() {
}
function init() {
// security token
add_action(
@ -27,7 +24,12 @@ class API {
'wp_ajax_nopriv_mailpoet',
array($this, 'setupPublic')
);
// Public API (Post)
add_action(
'admin_post_mailpoet',
array($this, 'setupPublic')
);
add_action(
'admin_post_nopriv_mailpoet',
array($this, 'setupPublic')
@ -102,12 +104,16 @@ class API {
try {
$endpoint = new $endpoint();
$response = $endpoint->$method($data);
$response->send();
if($doing_ajax) {
$response->send();
}
} catch(\Exception $e) {
$error_response = new ErrorResponse(
array($e->getCode() => $e->getMessage())
);
$error_response->send();
if($doing_ajax) {
$error_response = new ErrorResponse(
array($e->getCode() => $e->getMessage())
);
$error_response->send();
}
}
}