PluginProbe
SendWP / 0.0.2
SendWP v0.0.2
trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1 1.2.10 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.4.4 1.4.5 1.4.6 1.4.8
← All changes | includes/api/class.request.php +54 -63 1.4.50.0.2 View file →
@@ -1,64 +1,55 @@
1 -<?php
2 -
3 -namespace SendWP\API;
4 -
5 -class Request
6 -{
7 - protected $server_url;
8 - protected $endpoint;
9 - protected $client_name;
10 - protected $client_secret;
11 -
12 - public static function create( $endpoint )
13 - {
14 - $server_url = sendwp_get_server_url();
15 - $client_name = sendwp_get_client_name();
16 - $client_secret = sendwp_get_client_secret();
17 - return new self( $server_url, $endpoint, $client_name, $client_secret );
18 - }
19 -
20 - public function __construct( $server_url, $endpoint, $client_name, $client_secret )
21 - {
22 - $this->server_url = $server_url;
23 - $this->set_endpoint( $endpoint );
24 - $this->client_name = $client_name;
25 - $this->client_secret = $client_secret;
26 - }
27 -
28 - public function set_endpoint( $target )
29 - {
30 - $this->endpoint = 'wp-json/sendwp/' . $target;
31 - }
32 -
33 - public function request_url()
34 - {
35 - return $this->server_url . $this->endpoint;
36 - }
37 -
38 - public function post( $args )
39 - {
40 - return $this->request( 'POST', $args );
41 - }
42 -
43 - public function request( $method, $args )
44 - {
45 - $args[ 'method' ] = $method;
46 - $args['reject_unsafe_urls'] = false; // Whitelist requests to the service.
47 - $args[ 'headers' ][ 'x-sendwp-client-auth' ] = $this->get_auth_headers();
48 -
49 - if (! empty($_SERVER['HTTP_CLIENT_IP'])) {
50 - $args['headers']['x-forwarded-for'] = $_SERVER['HTTP_CLIENT_IP'];
51 - } elseif (! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
52 - $args['headers']['x-forwarded-for'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
53 - } else {
54 - $args['headers']['x-forwarded-for'] = $_SERVER['REMOTE_ADDR'];
55 - }
56 -
57 - return wp_remote_request( $this->request_url(), $args );
58 - }
59 -
60 - protected function get_auth_headers()
61 - {
62 - return 'Basic ' . base64_encode( $this->client_name . ':' . $this->client_secret );
63 - }
1 +<?php
2 +
3 +namespace SendWP\API;
4 +
5 +class Request
6 +{
7 + protected $server_url;
8 + protected $endpoint;
9 + protected $client_name;
10 + protected $client_secret;
11 +
12 + public static function create( $endpoint )
13 + {
14 + $server_url = sendwp_get_server_url();
15 + $client_name = sendwp_get_client_name();
16 + $client_secret = sendwp_get_client_secret();
17 + return new self( $server_url, $endpoint, $client_name, $client_secret );
18 + }
19 +
20 + public function __construct( $server_url, $endpoint, $client_name, $client_secret )
21 + {
22 + $this->server_url = $server_url;
23 + $this->set_endpoint( $endpoint );
24 + $this->client_name = $client_name;
25 + $this->client_secret = $client_secret;
26 + }
27 +
28 + public function set_endpoint( $target )
29 + {
30 + $this->endpoint = 'wp-json/sendwp/' . $target;
31 + }
32 +
33 + public function request_url()
34 + {
35 + return $this->server_url . $this->endpoint;
36 + }
37 +
38 + public function post( $args )
39 + {
40 + return $this->request( 'POST', $args );
41 + }
42 +
43 + public function request( $method, $args )
44 + {
45 + $args[ 'method' ] = $method;
46 + $args['reject_unsafe_urls'] = false; // Whitelist requests to the service.
47 + $args[ 'headers' ][ 'x-sendwp-client-auth' ] = $this->get_auth_headers();
48 + return wp_remote_request( $this->request_url(), $args );
49 + }
50 +
51 + protected function get_auth_headers()
52 + {
53 + return 'Basic ' . base64_encode( $this->client_name . ':' . $this->client_secret );
54 + }
64 55 }