Keine Beschreibung

UserFlags.php 994B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace MailPoet\API\JSON\v1;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\API\JSON\Endpoint as APIEndpoint;
  5. use MailPoet\API\JSON\Error as APIError;
  6. use MailPoet\Config\AccessControl;
  7. use MailPoet\Settings\UserFlagsController;
  8. use MailPoet\WP\Functions as WPFunctions;
  9. class UserFlags extends APIEndpoint {
  10. /** @var UserFlagsController */
  11. private $userFlags;
  12. public $permissions = [
  13. 'global' => AccessControl::ALL_ROLES_ACCESS,
  14. ];
  15. public function __construct(
  16. UserFlagsController $userFlags
  17. ) {
  18. $this->userFlags = $userFlags;
  19. }
  20. public function set(array $flags = []) {
  21. if (empty($flags)) {
  22. return $this->badRequest(
  23. [
  24. APIError::BAD_REQUEST =>
  25. WPFunctions::get()->__('You have not specified any user flags to be saved.', 'mailpoet'),
  26. ]);
  27. } else {
  28. foreach ($flags as $name => $value) {
  29. $this->userFlags->set($name, $value);
  30. }
  31. return $this->successResponse([]);
  32. }
  33. }
  34. }