PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.1
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.1
1.7.1 1.7.0 1.6.0 1.5.2 trunk 0.1 0.2.0 0.2.1 0.3 0.3.1 0.3.2 0.3.3 0.3.4 0.4 0.4.1 0.4.2 0.4.3 1.0 1.1 1.2 1.3.1 1.4.0 1.4.1 1.5.0 1.5.1 All 26 releases
flywp / includes / Api.php

Api.php in FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel 1.1, at includes/Api.php

64 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FlyWP;
4
5 /**
6 * API class.
7 *
8 * @since 1.0.0
9 */
10 class Api {
11
12 /**
13 * API constructor.
14 */
15 public function __construct() {
16 $router = flywp()->router;
17 $router->init();
18
19 new Api\Ping();
20
21 if ( ! $this->has_valid_key() ) {
22 return;
23 }
24
25 new Api\Plugins();
26 new Api\Themes();
27 new Api\Updates();
28 new Api\Fastcgi_Cache();
29 new Api\Health();
30 }
31
32 /**
33 * Check if API key is valid.
34 *
35 * @return bool
36 */
37 public function has_valid_key() {
38 if ( flywp()->has_key() && flywp()->get_key() === $this->get_bearer_token() ) {
39 return true;
40 }
41
42 return false;
43 }
44
45 /**
46 * Get bearer token from Authorization header.
47 *
48 * @return string|bool
49 */
50 public function get_bearer_token() {
51 if ( ! isset( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
52 return false;
53 }
54
55 $auth_header = $_SERVER['HTTP_AUTHORIZATION'];
56
57 if ( ! preg_match( '/Bearer\s(\S+)/', $auth_header, $matches ) ) {
58 return false;
59 }
60
61 return $matches[1];
62 }
63 }
64