Add user flags API endpoint [MAILPOET-1677]
This commit is contained in:
committed by
M. Shull
parent
33847397f3
commit
6218166ca1
41
lib/API/JSON/v1/UserFlags.php
Normal file
41
lib/API/JSON/v1/UserFlags.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\API\JSON\v1;
|
||||
|
||||
use MailPoet\API\JSON\Endpoint as APIEndpoint;
|
||||
use MailPoet\API\JSON\Error as APIError;
|
||||
use MailPoet\Config\AccessControl;
|
||||
use MailPoet\Services\Bridge;
|
||||
use MailPoet\Settings\UserFlags as UserFlagsController;
|
||||
use MailPoet\WP\Functions as WPFunctions;
|
||||
|
||||
if (!defined('ABSPATH')) exit;
|
||||
|
||||
class UserFlags extends APIEndpoint {
|
||||
|
||||
/** @var UserFlagsController */
|
||||
private $user_flags;
|
||||
|
||||
public $permissions = array(
|
||||
'global' => AccessControl::PERMISSION_MANAGE_SETTINGS
|
||||
);
|
||||
|
||||
function __construct(UserFlagsController $user_flags) {
|
||||
$this->user_flags = $user_flags;
|
||||
}
|
||||
|
||||
function set(array $flags = []) {
|
||||
if (empty($flags)) {
|
||||
return $this->badRequest(
|
||||
array(
|
||||
APIError::BAD_REQUEST =>
|
||||
WPFunctions::get()->__('You have not specified any user flags to be saved.', 'mailpoet')
|
||||
));
|
||||
} else {
|
||||
foreach ($flags as $name => $value) {
|
||||
$this->user_flags->set($name, $value);
|
||||
}
|
||||
return $this->successResponse([]);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user