Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/wordpres.../admin
File: class-remote-request.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* This class handles a post request being send to a given endpoint.
[8] Fix | Delete
*/
[9] Fix | Delete
class WPSEO_Remote_Request {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Holds the post method.
[13] Fix | Delete
*
[14] Fix | Delete
* @var string
[15] Fix | Delete
*/
[16] Fix | Delete
public const METHOD_POST = 'post';
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Holds the get method.
[20] Fix | Delete
*
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
public const METHOD_GET = 'get';
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Holds the endpoint to send the request to.
[27] Fix | Delete
*
[28] Fix | Delete
* @var string
[29] Fix | Delete
*/
[30] Fix | Delete
protected $endpoint = '';
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Holds the arguments to use in this request.
[34] Fix | Delete
*
[35] Fix | Delete
* @var array
[36] Fix | Delete
*/
[37] Fix | Delete
protected $args = [
[38] Fix | Delete
'blocking' => false,
[39] Fix | Delete
'timeout' => 2,
[40] Fix | Delete
];
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Holds the response error.
[44] Fix | Delete
*
[45] Fix | Delete
* @var WP_Error|null
[46] Fix | Delete
*/
[47] Fix | Delete
protected $response_error;
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Holds the response body.
[51] Fix | Delete
*
[52] Fix | Delete
* @var mixed
[53] Fix | Delete
*/
[54] Fix | Delete
protected $response_body;
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Sets the endpoint and arguments.
[58] Fix | Delete
*
[59] Fix | Delete
* @param string $endpoint The endpoint to send the request to.
[60] Fix | Delete
* @param array $args The arguments to use in this request.
[61] Fix | Delete
*/
[62] Fix | Delete
public function __construct( $endpoint, array $args = [] ) {
[63] Fix | Delete
$this->endpoint = $endpoint;
[64] Fix | Delete
$this->args = wp_parse_args( $this->args, $args );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Sets the request body.
[69] Fix | Delete
*
[70] Fix | Delete
* @param mixed $body The body to set.
[71] Fix | Delete
*
[72] Fix | Delete
* @return void
[73] Fix | Delete
*/
[74] Fix | Delete
public function set_body( $body ) {
[75] Fix | Delete
$this->args['body'] = $body;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Sends the data to the given endpoint.
[80] Fix | Delete
*
[81] Fix | Delete
* @param string $method The type of request to send.
[82] Fix | Delete
*
[83] Fix | Delete
* @return bool True when sending data has been successful.
[84] Fix | Delete
*/
[85] Fix | Delete
public function send( $method = self::METHOD_POST ) {
[86] Fix | Delete
switch ( $method ) {
[87] Fix | Delete
case self::METHOD_POST:
[88] Fix | Delete
$response = $this->post();
[89] Fix | Delete
break;
[90] Fix | Delete
case self::METHOD_GET:
[91] Fix | Delete
$response = $this->get();
[92] Fix | Delete
break;
[93] Fix | Delete
default:
[94] Fix | Delete
/* translators: %1$s expands to the request method */
[95] Fix | Delete
$response = new WP_Error( 1, sprintf( __( 'Request method %1$s is not valid.', 'wordpress-seo' ), $method ) );
[96] Fix | Delete
break;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
return $this->process_response( $response );
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
/**
[103] Fix | Delete
* Returns the value of the response error.
[104] Fix | Delete
*
[105] Fix | Delete
* @return WP_Error|null The response error.
[106] Fix | Delete
*/
[107] Fix | Delete
public function get_response_error() {
[108] Fix | Delete
return $this->response_error;
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
/**
[112] Fix | Delete
* Returns the response body.
[113] Fix | Delete
*
[114] Fix | Delete
* @return mixed The response body.
[115] Fix | Delete
*/
[116] Fix | Delete
public function get_response_body() {
[117] Fix | Delete
return $this->response_body;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
/**
[121] Fix | Delete
* Processes the given response.
[122] Fix | Delete
*
[123] Fix | Delete
* @param mixed $response The response to process.
[124] Fix | Delete
*
[125] Fix | Delete
* @return bool True when response is valid.
[126] Fix | Delete
*/
[127] Fix | Delete
protected function process_response( $response ) {
[128] Fix | Delete
if ( $response instanceof WP_Error ) {
[129] Fix | Delete
$this->response_error = $response;
[130] Fix | Delete
[131] Fix | Delete
return false;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
$this->response_body = wp_remote_retrieve_body( $response );
[135] Fix | Delete
[136] Fix | Delete
return ( wp_remote_retrieve_response_code( $response ) === 200 );
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
/**
[140] Fix | Delete
* Performs a post request to the specified endpoint with set arguments.
[141] Fix | Delete
*
[142] Fix | Delete
* @return WP_Error|array The response or WP_Error on failure.
[143] Fix | Delete
*/
[144] Fix | Delete
protected function post() {
[145] Fix | Delete
return wp_remote_post( $this->endpoint, $this->args );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
/**
[149] Fix | Delete
* Performs a post request to the specified endpoint with set arguments.
[150] Fix | Delete
*
[151] Fix | Delete
* @return WP_Error|array The response or WP_Error on failure.
[152] Fix | Delete
*/
[153] Fix | Delete
protected function get() {
[154] Fix | Delete
return wp_remote_get( $this->endpoint, $this->args );
[155] Fix | Delete
}
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function