Repository navigation
Conversation
Add tests demonstrating that a `wp_headers` filter or `send_headers` action callback can use `is_sitemap()` to add a header, such as `X-Robots-Tag`, to core sitemap responses. `WP::main()` runs `query_posts()` before `send_headers()`, so the conditional tag works there, and both hooks fire before `WP_Sitemaps::render_sitemaps()` runs on `template_redirect`. The tests also document that `is_sitemap()` is true for sitemap routes that `render_sitemaps()` later turns into a 404. Follow-up to r54250, r62664, r64073. See #60552. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds tests showing that the existing
wp_headersfilter andsend_headersaction, combined withis_sitemap(), can add a header such asX-Robots-Tagto core sitemap responses without thewp_doing_sitemapsaction proposed in #12044.They pass on trunk because of how requests are handled now:
WP::main()runsquery_posts()beforesend_headers(), sois_sitemap()(r62664) works inside both hooks.template_redirect, which is whereWP_Sitemaps::render_sitemaps()sendsContent-Typeand the XML.is_sitemap()is true.The new
Tests_Sitemaps_SendHeadersclass covers:wp_headerscallback addsX-Robots-Tagon the index, posts (post, page, paged), taxonomies and users sitemaps.send_headers:is_sitemap()is true inside thesend_headersaction (the approach in comment:6).wp_headersfires before any sitemap entry is rendered, and the response is a 200 with<urlset>output.is_sitemap()is also true for sitemap routes thatrender_sitemaps()later turns into a 404, such as an unregistered provider. The action proposed in #60552 - Add wp_doing_sitemaps action hook to WP_Sitemaps::render_sitemaps() #12044 fires before the provider, subtype and page checks, so it has the same behavior.To check that the tests depend on this ordering, I temporarily moved
send_headers()back in front ofquery_posts(). With that change, 9 of the 10 tests fail.The tests can only check the headers passed through
wp_headersand the order of the hooks, because PHP'sheader()has no effect under the CLI.Trac ticket: https://core.trac.wordpress.org/ticket/60552
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Analysis of the ticket and confirming the core request flow, writing the tests and this description; reviewed by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code