PluginProbe
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel / 1.4.0
FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel v1.4.0
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 1.4.0, at includes/FlyApi.php

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