class-cache-controller.php
10 months ago
class-css-controller.php
10 months ago
class-domainshift-controller.php
10 months ago
class-key-controller.php
10 months ago
class-log-controller.php
10 months ago
class-option-controller.php
10 months ago
class-rest-controller.php
10 months ago
class-rest-controller.php
59 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SuperbAddons\Data\Controllers; |
| 4 | |
| 5 | defined('ABSPATH') || exit(); |
| 6 | |
| 7 | class RestController |
| 8 | { |
| 9 | const NAMESPACE = 'superbaddons'; |
| 10 | const TOKEN = 'SPBAV1iZV7b674&p7%8#v#Z'; |
| 11 | |
| 12 | private static $Routes = array(); |
| 13 | |
| 14 | public static function AddRoute($route, $args) |
| 15 | { |
| 16 | self::$Routes[] = array( |
| 17 | "route" => $route, |
| 18 | "args" => $args |
| 19 | ); |
| 20 | } |
| 21 | |
| 22 | public static function RegisterRoutes() |
| 23 | { |
| 24 | add_action('rest_api_init', function () { |
| 25 | foreach (self::$Routes as $Route) { |
| 26 | register_rest_route(self::NAMESPACE, $Route['route'], $Route['args']); |
| 27 | } |
| 28 | }); |
| 29 | } |
| 30 | |
| 31 | public static function GetArgsHeadersArray($args = array()) |
| 32 | { |
| 33 | $headers = array( |
| 34 | 'X-Superb-Auth' => 'Token ' . self::TOKEN |
| 35 | ); |
| 36 | if (isset($args['headers']) && is_array($args['headers'])) { |
| 37 | foreach ($args['headers'] as $key => $value) { |
| 38 | $headers[$key] = $value; |
| 39 | } |
| 40 | } |
| 41 | return array_merge($args, array( |
| 42 | 'timeout' => 60, |
| 43 | 'headers' => $headers |
| 44 | )); |
| 45 | } |
| 46 | |
| 47 | public static function IsAcceptableConnection($response) |
| 48 | { |
| 49 | if (!is_wp_error($response) && wp_remote_retrieve_response_code($response) === 200) { |
| 50 | if (!isset($response['headers']) || (isset($response['headers']['server']) && strpos($response['headers']['server'], 'imunify360') !== false)) { |
| 51 | return false; |
| 52 | } |
| 53 | return true; |
| 54 | } |
| 55 | |
| 56 | return false; |
| 57 | } |
| 58 | } |
| 59 |