#50643 closed defect (bug) (fixed)
Ensure correct HTTP status when sitemaps are disabled
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | 5.5 |
Component: | Sitemaps | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
To reproduce:
Add add_filter( 'wp_sitemaps_enabled', '__return_false' )
in a plugin to disable sitemaps.
Expectation:
https://example.com/wp-sitemap.xml
returns a 404 status and displays a 404 page.
Actual result:
https://example.com/wp-sitemap.xml
returns a 200 status and displays the homepage.
This is because the rewrite rules are still there, but the sitemaps are actually disabled and wp_sitemaps_get_server()
isn't initializing the sitemaps due to the filter
After flushing permalinks the result is as expected: a 404 status & page.
This inconsistent behavior should be fixed.
Attachments (4)
Change History (17)
This ticket was mentioned in Slack in #core-sitemaps by swissspidy. View the logs.
5 years ago
This ticket was mentioned in Slack in #core-sitemaps by swissspidy. View the logs.
5 years ago
This ticket was mentioned in PR #405 on WordPress/wordpress-develop by donmhico.
5 years ago
#8
- Keywords has-unit-tests added; needs-unit-tests removed
Return 404 on sitemap page without the need to flush permalinks. This PR is based on swissspidy's patch. I just added a unit test.
Trac ticket: https://core.trac.wordpress.org/ticket/50643
#9
@
5 years ago
The PR I attached - https://github.com/WordPress/wordpress-develop/pull/405 - includes Unit tests for @swissspidy's patch (thank you by the way).
#10
@
5 years ago
- Keywords commit added; needs-testing removed
Thanks all!
I extended the tests a little bit in the latest patch, and I think this is good to go now.
Tested this out and works as expected. Updating the patch with inline docs for the filter explaining the rewrites would still be present.