options->http_auth(); if ( null === $auth || ! is_array( $request ) || ! $this->is_site_request( $request ) ) { return $request; } $request['args']['headers']['Authorization'] = 'Basic ' . base64_encode( $auth['user'] . ':' . $auth['password'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Required by the HTTP Basic scheme. return $request; } /** * Whether a request has an address and arguments, and the address belongs to this site. * * @param array $request The request. * @return bool True when it does. */ private function is_site_request( array $request ): bool { return isset( $request['url'] ) && is_array( $request['args'] ?? null ) && $this->is_this_site( (string) $request['url'] ); } /** * Whether an address is on the site's own host. * * @param string $url Address. * @return bool True when the host matches the home or site address. */ private function is_this_site( string $url ): bool { $host = strtolower( (string) wp_parse_url( $url, PHP_URL_HOST ) ); return '' !== $host && in_array( $host, array( strtolower( (string) wp_parse_url( home_url(), PHP_URL_HOST ) ), strtolower( (string) wp_parse_url( site_url(), PHP_URL_HOST ) ) ), true ); } }