Add JSON endpoint for CAPTCHA rendering

To be used inside WP/WC registration form to construct URL for CAPTCHA page.

[MAILPOET-6325]
This commit is contained in:
Mustapha Hadid
2024-11-15 21:50:45 +03:00
committed by David Remer
parent d2ebfba8c3
commit df171fdcc7
7 changed files with 101 additions and 9 deletions

View File

@@ -6,6 +6,7 @@ use MailPoet\WP\Functions as WPFunctions;
abstract class Response {
const STATUS_OK = 200;
const REDIRECT = 302;
const STATUS_BAD_REQUEST = 400;
const STATUS_UNAUTHORIZED = 401;
const STATUS_FORBIDDEN = 403;
@@ -15,16 +16,20 @@ abstract class Response {
public $status;
public $meta;
public $location;
public function __construct(
$status,
$meta = []
) {
public function __construct($status, $meta = [], $location = null) { // phpcs:ignore
$this->status = $status;
$this->meta = $meta;
$this->location = $location;
}
public function send() {
if ($this->status === self::REDIRECT && $this->location) {
header("Location: " . $this->location, true, $this->status);
exit;
}
WPFunctions::get()->statusHeader($this->status);
$data = $this->getData();