Changeset 63570 for trunk/src/wp-includes/sitemaps/class-wp-sitemaps.php
- Timestamp:
- 09/09/2026 10:24:50 PM (27 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/sitemaps/class-wp-sitemaps.php
r59229 r63570 158 158 * 159 159 * @since 5.5.0 160 *161 * @global WP_Query $wp_query WordPress Query object.162 160 */ 163 161 public function render_sitemaps() { 164 global $wp_query; 162 /* 163 * Bail early if this isn't a sitemap or stylesheet route. 164 * 165 * This runs on every front-end request, so it comes before any 166 * sanitizing. The raw query vars are tested here, matching 167 * WP::handle_404(), which exempts sitemap requests from its own 404 on 168 * the same basis. Testing the sanitized values instead would let a 169 * request that handle_404() exempted fall through both, leaving it a 200. 170 */ 171 if ( ! get_query_var( 'sitemap' ) && ! get_query_var( 'sitemap-stylesheet' ) ) { 172 return; 173 } 165 174 166 175 $sitemap = sanitize_text_field( get_query_var( 'sitemap' ) ); … … 169 178 $paged = absint( get_query_var( 'paged' ) ); 170 179 171 // Bail early if this isn't a sitemap or stylesheet route.180 // Force a 404 and bail early if the route did not survive sanitizing. 172 181 if ( ! ( $sitemap || $stylesheet_type ) ) { 182 $this->send_404(); 173 183 return; 174 184 } 175 185 176 186 if ( ! $this->sitemaps_enabled() ) { 177 $wp_query->set_404(); 178 status_header( 404 ); 187 $this->send_404(); 179 188 return; 180 189 } … … 182 191 // Render stylesheet if this is stylesheet route. 183 192 if ( $stylesheet_type ) { 193 // Force a 404 and bail early if the stylesheet type is not recognized. 194 if ( ! in_array( $stylesheet_type, array( 'sitemap', 'index' ), true ) ) { 195 $this->send_404(); 196 return; 197 } 198 184 199 $stylesheet = new WP_Sitemaps_Stylesheet(); 185 200 … … 198 213 $provider = $this->registry->get_provider( $sitemap ); 199 214 215 // Force a 404 and bail early if the requested provider is not registered. 200 216 if ( ! $provider ) { 217 $this->send_404(); 201 218 return; 202 219 } … … 210 227 // Force a 404 and bail early if no URLs are present. 211 228 if ( empty( $url_list ) ) { 212 $wp_query->set_404(); 213 status_header( 404 ); 229 $this->send_404(); 214 230 return; 215 231 } … … 217 233 $this->renderer->render_sitemap( $url_list ); 218 234 exit; 235 } 236 237 /** 238 * Sends a 404 for a sitemap route that cannot be served. 239 * 240 * WP::handle_404() exempts sitemap requests, so every sitemap 404 is issued 241 * here instead. That includes the no-cache headers handle_404() sends with 242 * its own 404, so an intermediary does not retain a 404 for a route that 243 * becomes valid once the site has more content. 244 * 245 * @since 7.1.1 246 * 247 * @global WP_Query $wp_query WordPress Query object. 248 */ 249 private function send_404(): void { 250 global $wp_query; 251 252 $wp_query->set_404(); 253 status_header( 404 ); 254 nocache_headers(); 219 255 } 220 256
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)