/** * Make a HTTP POST request to the provided URL * @param string $url URL to make the request to * @param array $data Data to send with the request, default is a blank array * @param boolean $isJSON optional|TRUE Whether our data is JSON encoded or not * @param string $method optional|POST Sets the header HTTP request method * @return wp_response Results of the POST request */ static function post($url, $data, $isJSON = TRUE, $method = 'POST') { $escapedUrl = esc_url_raw($url); $default_data = array('method' => $method, 'timeout' => 10); if ($isJSON) { $default_data['headers'] = array('content-type' => 'application/json; charset=UTF-8'); } $args = array_merge($default_data, $data); $response = wp_remote_post($escapedUrl, $args); $newUrl = ThePlatform_API_HTTP::check_for_auth_error($response, $url); if ($newUrl === false) { return $response; } else { return ThePlatform_API_HTTP::post($newUrl, $data, $isJSON, $method); } }