PluginProbe
MailPoet – Newsletters, Email Marketing, and Automation / 3.59.2
MailPoet – Newsletters, Email Marketing, and Automation v3.59.2
5.38.0 5.37.0 5.36.1 5.36.0 5.35.1 5.35.0 5.34.3 5.34.2 5.34.1 5.34.0 5.33.1 5.33.0 5.32.0 5.31.0 5.30.0 5.29.0 5.28.1 5.28.0 5.27.0 5.26.0 5.26.1 5.25.0 5.24.0 4.43.0 4.43.1 All 542 releases
mailpoet / lib / API / JSON / Response.php

Response.php in MailPoet – Newsletters, Email Marketing, and Automation 3.59.2, at lib/API/JSON/Response.php

48 lines 1008 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MailPoet\API\JSON;
4
5 if (!defined('ABSPATH')) exit;
6
7
8 use MailPoet\WP\Functions as WPFunctions;
9
10 abstract class Response {
11 const STATUS_OK = 200;
12 const STATUS_BAD_REQUEST = 400;
13 const STATUS_UNAUTHORIZED = 401;
14 const STATUS_FORBIDDEN = 403;
15 const STATUS_NOT_FOUND = 404;
16 const STATUS_CONFLICT = 409;
17 const STATUS_UNKNOWN = 500;
18
19 public $status;
20 public $meta;
21
22 public function __construct($status, $meta = []) {
23 $this->status = $status;
24 $this->meta = $meta;
25 }
26
27 public function send() {
28 WPFunctions::get()->statusHeader($this->status);
29
30 $data = $this->getData();
31 $response = [];
32
33 if (!empty($this->meta)) {
34 $response['meta'] = $this->meta;
35 }
36 if ($data === null) {
37 $data = [];
38 }
39 $response = array_merge($response, $data);
40
41 @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
42 echo WPFunctions::get()->wpJsonEncode($response);
43 die();
44 }
45
46 public abstract function getData();
47 }
48