PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 0.3
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v0.3
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 / FlyApi.php

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

103 lines 2.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 class FlyApi {
6
7 /**
8 * Get the site's info.
9 *
10 * @return array|false
11 */
12 public function site_info() {
13 return $this->get( '/info' );
14 }
15
16 /**
17 * Set the site's cache status.
18 *
19 * @param string $action
20 *
21 * @return array|false
22 */
23 public function cache_toggle( $action = 'enable' ) {
24 return $this->post(
25 '/cache-toggle',
26 [
27 'action' => $action,
28 ]
29 );
30 }
31
32 /**
33 * Get the API endpoint.
34 *
35 * @return string
36 */
37 protected function get_endpoint() {
38 return apply_filters( 'flywp_api_endpoint', 'https://app.flywp.io/api/site-api' );
39 }
40
41 /**
42 * Send a GET request to the API.
43 *
44 * @param string $path
45 *
46 * @return array|false
47 */
48 public function get( $path ) {
49 $url = $this->get_endpoint() . $path;
50
51 $response = wp_remote_get(
52 $url,
53 [
54 'headers' => [
55 'Authorization' => 'Bearer ' . flywp()->get_key(),
56 ],
57 ]
58 );
59
60 if ( is_wp_error( $response ) ) {
61 // Handle error if needed
62 return false;
63 }
64
65 $body = wp_remote_retrieve_body( $response );
66 $data = json_decode( $body, true );
67
68 return $data;
69 }
70
71 /**
72 * Send a POST request to the API.
73 *
74 * @param string $path
75 * @param array $data
76 *
77 * @return array|false
78 */
79 public function post( $path, $data = [] ) {
80 $url = $this->get_endpoint() . $path;
81
82 $response = wp_remote_post(
83 $url,
84 [
85 'headers' => [
86 'Authorization' => 'Bearer ' . flywp()->get_key(),
87 ],
88 'body' => $data,
89 ]
90 );
91
92 if ( is_wp_error( $response ) ) {
93 // Handle error if needed
94 return false;
95 }
96
97 $body = wp_remote_retrieve_body( $response );
98 $data = json_decode( $body, true );
99
100 return $data;
101 }
102 }
103