PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / vendor / appsero / client / src / Client.php

Client.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at vendor/appsero/client/src/Client.php

286 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Appsero;
4
5 /**
6 * Appsero Client
7 *
8 * This class is necessary to set project data
9 */
10 class Client {
11
12 /**
13 * The client version
14 *
15 * @var string
16 */
17 public $version = '1.2.4';
18
19 /**
20 * Hash identifier of the plugin
21 *
22 * @var string
23 */
24 public $hash;
25
26 /**
27 * Name of the plugin
28 *
29 * @var string
30 */
31 public $name;
32
33 /**
34 * The plugin/theme file path
35 *
36 * @example .../wp-content/plugins/test-slug/test-slug.php
37 *
38 * @var string
39 */
40 public $file;
41
42 /**
43 * Main plugin file
44 *
45 * @example test-slug/test-slug.php
46 *
47 * @var string
48 */
49 public $basename;
50
51 /**
52 * Slug of the plugin
53 *
54 * @example test-slug
55 *
56 * @var string
57 */
58 public $slug;
59
60 /**
61 * The project version
62 *
63 * @var string
64 */
65 public $project_version;
66
67 /**
68 * The project type
69 *
70 * @var string
71 */
72 public $type;
73
74 /**
75 * Textdomain
76 *
77 * @var string
78 */
79 public $textdomain;
80
81 /**
82 * The Object of Insights Class
83 *
84 * @var object
85 */
86 private $insights;
87
88 /**
89 * The Object of Updater Class
90 *
91 * @var object
92 */
93 private $updater;
94
95 /**
96 * The Object of License Class
97 *
98 * @var object
99 */
100 private $license;
101
102 /**
103 * Initialize the class
104 *
105 * @param string $hash hash of the plugin
106 * @param string $name readable name of the plugin
107 * @param string $file main plugin file path
108 */
109 public function __construct( $hash, $name, $file ) {
110 $this->hash = $hash;
111 $this->name = $name;
112 $this->file = $file;
113
114 $this->set_basename_and_slug();
115 }
116
117 /**
118 * Initialize insights class
119 *
120 * @return Appsero\Insights
121 */
122 public function insights() {
123 if ( ! class_exists( __NAMESPACE__ . '\Insights' ) ) {
124 require_once __DIR__ . '/Insights.php';
125 }
126
127 // if already instantiated, return the cached one
128 if ( $this->insights ) {
129 return $this->insights;
130 }
131
132 $this->insights = new Insights( $this );
133
134 return $this->insights;
135 }
136
137 /**
138 * Initialize plugin/theme updater
139 *
140 * @return Appsero\Updater
141 */
142 public function updater() {
143 if ( ! class_exists( __NAMESPACE__ . '\Updater' ) ) {
144 require_once __DIR__ . '/Updater.php';
145 }
146
147 // if already instantiated, return the cached one
148 if ( $this->updater ) {
149 return $this->updater;
150 }
151
152 $this->updater = new Updater( $this );
153
154 return $this->updater;
155 }
156
157 /**
158 * Initialize license checker
159 *
160 * @return Appsero\License
161 */
162 public function license() {
163 if ( ! class_exists( __NAMESPACE__ . '\License' ) ) {
164 require_once __DIR__ . '/License.php';
165 }
166
167 // if already instantiated, return the cached one
168 if ( $this->license ) {
169 return $this->license;
170 }
171
172 $this->license = new License( $this );
173
174 return $this->license;
175 }
176
177 /**
178 * API Endpoint
179 *
180 * @return string
181 */
182 public function endpoint() {
183 $endpoint = apply_filters( 'appsero_endpoint', 'https://api.appsero.com' );
184
185 return trailingslashit( $endpoint );
186 }
187
188 /**
189 * Set project basename, slug and version
190 *
191 * @return void
192 */
193 protected function set_basename_and_slug() {
194 if ( strpos( $this->file, WP_CONTENT_DIR . '/themes/' ) === false ) {
195 $this->basename = plugin_basename( $this->file );
196
197 list( $this->slug, $mainfile ) = explode( '/', $this->basename );
198
199 require_once ABSPATH . 'wp-admin/includes/plugin.php';
200
201 $plugin_data = get_plugin_data( $this->file );
202
203 $this->project_version = $plugin_data['Version'];
204 $this->type = 'plugin';
205 } else {
206 $this->basename = str_replace( WP_CONTENT_DIR . '/themes/', '', $this->file );
207
208 list( $this->slug, $mainfile ) = explode( '/', $this->basename );
209
210 $theme = wp_get_theme( $this->slug );
211
212 $this->project_version = $theme->version;
213 $this->type = 'theme';
214 }
215
216 $this->textdomain = $this->slug;
217 }
218
219 /**
220 * Send request to remote endpoint
221 *
222 * @param array $params
223 * @param string $route
224 *
225 * @return array|WP_Error array of results including HTTP headers or WP_Error if the request failed
226 */
227 public function send_request( $params, $route, $blocking = false ) {
228 $url = $this->endpoint() . $route;
229
230 $headers = [
231 'user-agent' => 'Appsero/' . md5( esc_url( home_url() ) ) . ';',
232 'Accept' => 'application/json',
233 ];
234
235 $response = wp_remote_post(
236 $url,
237 [
238 'method' => 'POST',
239 'timeout' => 30,
240 'redirection' => 5,
241 'httpversion' => '1.0',
242 'blocking' => $blocking,
243 'headers' => $headers,
244 'body' => array_merge( $params, [ 'client' => $this->version ] ),
245 'cookies' => [],
246 ]
247 );
248
249 return $response;
250 }
251
252 /**
253 * Check if the current server is localhost
254 *
255 * @return bool
256 */
257 public function is_local_server() {
258 $is_local = isset( $_SERVER['REMOTE_ADDR'] ) && in_array( $_SERVER['REMOTE_ADDR'], [ '127.0.0.1', '::1' ], true );
259
260 return apply_filters( 'appsero_is_local', $is_local );
261 }
262
263 /**
264 * Translate function _e()
265 */
266 // phpcs:ignore
267 public function _etrans( $text ) {
268 call_user_func( '_e', $text, $this->textdomain );
269 }
270
271 /**
272 * Translate function __()
273 */
274 // phpcs:ignore
275 public function __trans( $text ) {
276 return call_user_func( '__', $text, $this->textdomain );
277 }
278
279 /**
280 * Set project textdomain
281 */
282 public function set_textdomain( $textdomain ) {
283 $this->textdomain = $textdomain;
284 }
285 }
286