$headers)); $this->error_handle($response, $throwWhenNot200); try { return $response['body']; } catch(\Exception $e) { return null; } } public function post($url, array $data = array(), array $headers = array(), $throwWhenNot200 = false) { $response = wp_remote_post($url , array('body' => $data, 'headers' => $headers)); $this->error_handle($response, $throwWhenNot200); try { return $response['body']; } catch(\Exception $e) { return null; } } private function error_handle($response, $throwWhenNot200) { if ($throwWhenNot200) { if (is_wp_error($response)) { throw new NetworkErrorException('WP_Error: ' . $response->get_error_message()); } elseif ($response['response']['code'] != 200) { throw new NetworkErrorException('Response code is not 200', $response['response']['code']); } } } }