[wp-trac] [WordPress Trac] #56068: Send HTTP headers after querying posts in WP::main()
WordPress Trac
noreply at wordpress.org
Fri Jun 24 13:05:30 UTC 2022
#56068: Send HTTP headers after querying posts in WP::main()
----------------------------+----------------------------------------
Reporter: SergeyBiryukov | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Bootstrap/Load | Version:
Severity: normal | Keywords: has-patch needs-unit-tests
Focuses: |
----------------------------+----------------------------------------
When trying to add or adjust some HTTP headers via the `wp_headers` filter
or `send_headers` action, the `$wp_query` global is mostly empty and
conditional tags don't work as expected, as posts have not been queried
yet.
The earliest action where conditional tags like `is_front_page()` work
correctly is currently `wp`.
In a discussion with @jonoaldersonwp and @joostdevalk it was pointed out
that moving the `send_headers()` call after `query_posts()` in
`WP::main()` would provide better context and more flexibility when
manipulating HTTP headers. Implementing that seems to work in my testing,
and all existing unit tests still pass.
If that happens, we could also move the `X-Pingback` header, which is
currently [source:tags/6.0/src/wp-includes/class-wp.php?marks=704-707#L702
sent in handle_404()] after posts have been queried, as of [34442] /
#20226, to a more appropriate place, which is `send_headers()` :)
However, that means sending headers after `WP_Query` runs all the post
queries, filters, etc. and I'm curious if there are any performance
considerations that should be taken into account here.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/56068>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list