#60552 closed defect (bug) (maybelater)
Add hook to WP_Sitemaps::render_sitemaps()
| Reported by: | Cybr | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Sitemaps | Version: | |
| Severity: | normal | Keywords: | has-patch reporter-feedback close |
| Cc: | Focuses: |
Description
Currently, we cannot tweak the sitemap's content parameters or headers.
To allow this without having to test whether the sitemap is outputting (there's currently no proper way, see #51543 and #56954), in WP_Sitemaps::render_sitemaps(), after the sitemaps_enabled() defense clause, add a hook wp_doing_sitemap.
For example
if ( ! $this->sitemaps_enabled() ) { $wp_query->set_404(); status_header( 404 ); return; } // Render stylesheet if this is stylesheet route. if ( $stylesheet_type ) { ...
Becomes
if ( ! $this->sitemaps_enabled() ) { $wp_query->set_404(); status_header( 404 ); return; } do_action( 'wp_doing_sitemaps' ); // Render stylesheet if this is stylesheet route. if ( $stylesheet_type ) { ...
Change History (10)
This ticket was mentioned in PR #12044 on WordPress/wordpress-develop by @masteradhoc.
3 months ago
#1
- Keywords has-patch added
#2
@
3 months ago
Hey @Cybr
Can you check the proposed PR (basically your suggestion) and see if this still suits your needs?
@Cybr commented on PR #12044:
3 months ago
#3
LGTM.
We may also want to consider adding a WP_Query variable to improve cohesion. See: https://core.trac.wordpress.org/ticket/51117#comment:7.
#5
@
8 weeks ago
- Keywords reporter-feedback added
Please provide an example of what this enabled which can't be done with current hooks combined with the new is_sitemap() function.
#6
@
8 weeks ago
- Keywords close added
If you want to send your own header in sitemap responses, you can do so as with the following, due to #51543:
<?php add_action( 'send_headers', function () { if ( function_exists( 'is_sitemap' ) && is_sitemap() ) { header( 'X-My-Sitemap-Header: true' ); } } );
This ticket was mentioned in Slack in #core by adrianduffell. View the logs.
7 weeks ago
#8
@
7 weeks ago
This was discussed in today's bug scub. It may still be possible to make it in the 7.1 beta cycle but needs a final review.
#9
@
7 weeks ago
- Milestone 7.1
- Resolution → maybelater
- Status new → closed
I'm closing as maybelater because I haven't seen that the desired result can't be achieved with existing hooks, per my comment.
@masteradhoc commented on PR #12044:
6 weeks ago
#10
As this has been closed as maybelater i'll close this PR for the moment. Happy to reopen anytime.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Add a
wp_doing_sitemapsaction hook toWP_Sitemaps::render_sitemaps()to allow plugins to modify HTTP headers or set up state before sitemap output begins.Trac ticket: https://core.trac.wordpress.org/ticket/60552
## Use of AI Tools
-