plugin_version = $plugin_version; } public function get( string $url, array $headers, int $maximum_bytes, int $timeout_seconds ): array { if ( $maximum_bytes < 2 || $maximum_bytes > 8388608 || $timeout_seconds < 1 || $timeout_seconds > 30 ) { throw new \InvalidArgumentException( 'external_transport_budget_invalid' ); } $host = wp_parse_url( $url, PHP_URL_HOST ); if ( 'https' !== wp_parse_url( $url, PHP_URL_SCHEME ) || ! in_array( $host, array( 'api.wordpress.org', 'downloads.wordpress.org' ), true ) ) { throw new \InvalidArgumentException( 'external_transport_destination_denied' ); } $headers['Accept'] = 'application/json'; $headers['User-Agent'] = '320px-Site-Audit/' . $this->plugin_version; $headers['Cache-Control'] = 'no-store'; $response = wp_safe_remote_get( $url, array( 'timeout' => $timeout_seconds, 'redirection' => 0, 'sslverify' => true, 'headers' => $headers, 'limit_response_size' => $maximum_bytes, ) ); if ( is_wp_error( $response ) ) { throw new ExternalRequestException( 'external_request_failed' ); } $status = (int) wp_remote_retrieve_response_code( $response ); $body = (string) wp_remote_retrieve_body( $response ); if ( strlen( $body ) > $maximum_bytes ) { throw new ExternalRequestException( 'external_response_too_large' ); } return array( 'status' => $status, 'body' => $body, ); } }