- added APIAccess class to define access levels of API Endpoints (permissions) - use "mailpoet_token" for all nonce (just as before) - merged setupPublic/setupAdmin methods in API in order to avoid duplication - check permission if access level is not all - fixed ABSPATH check in some classes
35 lines
869 B
PHP
35 lines
869 B
PHP
<?php
|
|
namespace MailPoet\API;
|
|
|
|
if(!defined('ABSPATH')) exit;
|
|
|
|
abstract class Endpoint {
|
|
|
|
public $permissions = array();
|
|
|
|
function successResponse(
|
|
$data = array(), $meta = array(), $status = Response::STATUS_OK
|
|
) {
|
|
return new SuccessResponse($data, $meta, $status);
|
|
}
|
|
|
|
function errorResponse(
|
|
$errors = array(), $meta = array(), $status = Response::STATUS_NOT_FOUND
|
|
) {
|
|
if(empty($errors)) {
|
|
$errors = array(
|
|
Error::UNKNOWN => __('An unknown error occurred.', 'mailpoet')
|
|
);
|
|
}
|
|
return new ErrorResponse($errors, $meta, $status);
|
|
}
|
|
|
|
function badRequest($errors = array(), $meta = array()) {
|
|
if(empty($errors)) {
|
|
$errors = array(
|
|
Error::BAD_REQUEST => __('Invalid request parameters.', 'mailpoet')
|
|
);
|
|
}
|
|
return new ErrorResponse($errors, $meta, Response::STATUS_BAD_REQUEST);
|
|
}
|
|
} |