} $request * @param callable(int, string): (array|ApiError) $decode * @return array|ApiError */ function send(array $request, callable $decode) { $url = Api::BASE_URL . $request['path'] . '?' . http_build_query(array_column($request['query'], 1, 0)); $response = wp_remote_get($url, [ 'timeout' => TIMEOUT_SECONDS, // A redirect would carry the key to another host, so none is followed. 'redirection' => 0, 'headers' => ['X-API-Key' => api_key()], ]); if (is_wp_error($response)) { return new ApiError(0, 'transport_error', $response->get_error_message()); } return $decode((int) wp_remote_retrieve_response_code($response), wp_remote_retrieve_body($response)); }