normalize_path( $request_uri ); if ( $request_path !== $this->normalize_path( $expected ) ) { return; } status_header( 200 ); header( 'Content-Type: text/plain; charset=utf-8' ); header( 'Cache-Control: public, max-age=3600' ); // IndexNow requires the response body to be the raw key, no escaping. // Key is constrained at save time by Settings::sanitize() to ^[a-zA-Z0-9-]+$. echo $key; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- IndexNow protocol; see comment above. exit; } /** * Normalize a URL/path string for comparison. * * @param string $path Requested path. * @return string */ private function normalize_path( string $path ): string { $parsed = wp_parse_url( $path, PHP_URL_PATH ); $parsed = is_string( $parsed ) ? $parsed : $path; $parsed = '/' . ltrim( $parsed, '/' ); return untrailingslashit( $parsed ); } }