# sendwp/1.2.8/includes/api/class.request.php

SendWP, version 1.2.8. 109 lines.

- Page: https://pluginprobe.com/plugins/sendwp/1.2.8/code/includes/api/class.request.php
- Raw: https://pluginprobe.com/plugins/sendwp/1.2.8/raw/includes/api/class.request.php
- Modified: 2022-05-30T19:40:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/sendwp/1.2.8/code/includes/api/class.request.php#L10-L20`.

```php
<?php

namespace SendWP\API;

class Request {
	protected $server_url;
	protected $endpoint;
	protected $client_name;
	protected $client_secret;

	/**
	 * Create Request
	 *
	 * @param String $endpoint
	 *
	 * @return Self
	 */
	public static function create( $endpoint ) {
		$server_url    = sendwp_get_server_url();
		$client_name   = sendwp_get_client_name();
		$client_secret = sendwp_get_client_secret();

		return new self( $server_url, $endpoint, $client_name, $client_secret );
	}

	/**
	 * Constructor
	 *
	 * @param String $server_url
	 * @param String $endpoint
	 * @param String $client_name
	 * @param String $client_secret
	 *
	 * @return Void
	 */
	public function __construct( $server_url, $endpoint, $client_name, $client_secret ) {
		$this->server_url = $server_url;

		$this->set_endpoint($endpoint);

		$this->client_name   = $client_name;
		$this->client_secret = $client_secret;
	}

	/**
	 * Set the Request Endpoint
	 *
	 * @param String $target
	 *
	 * @return Void
	 */
	public function set_endpoint( $target ) {
		$this->endpoint = 'wp-json/sendwp/' . $target;
	}

	/**
	 * Return the request URL
	 *
	 * @return String
	 */
	public function request_url() {
		return $this->server_url . $this->endpoint;
	}

	/**
	 * Return the post request
	 *
	 * @param Array $args
	 *
	 * @return Self
	 */
	public function post( $args ) {
		return $this->request( 'POST', $args );
	}

	/**
	 * Set the request
	 *
	 * @param String $method
	 * @param Array $args
	 *
	 * @return WP_REMOTE_REQUEST
	 */
	public function request( $method, $args ) {
		$args['method']                          = $method;
		$args['reject_unsafe_urls']              = false; // Whitelist requests to the service.
		$args['headers']['x-sendwp-client-auth'] = $this->get_auth_headers();

		if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
			$args['headers']['x-forwarded-for'] = $_SERVER['HTTP_CLIENT_IP'];
		} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
			$args['headers']['x-forwarded-for'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
		} else {
			$args['headers']['x-forwarded-for'] = $_SERVER['REMOTE_ADDR'];
		}

		return wp_remote_request( $this->request_url(), $args );
	}

	/**
	 * Get the authentication headers
	 *
	 * @return String
	 */
	protected function get_auth_headers() {
		return 'Basic ' . base64_encode( $this->client_name . ':' . $this->client_secret );
	}
}

```
