Fix: Core sitemaps rendered with HTTP 404 status when no post. - #13240
Fix: Core sitemaps rendered with HTTP 404 status when no post. #13240tewariharish wants to merge 5 commits into
Conversation
Update outdated Chrome documentation link in WP_Site_Icon
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| * Prevents core from issuing a 404 status header on valid sitemap requests | ||
| * when no standard blog posts exist. | ||
| * | ||
| * @since 6.8.0 |
update the version
|
This was discussed in today’s bug scrub for 7.1.1. We recommend closing it in favor of #13247 as that one doesn't need a filter. Your efforts on the PR are much appreciated though, @tewariharish 🙏 |
westonruter
left a comment
There was a problem hiding this comment.
A test should be added for this.
| * @param WP_Query $query The global WP_Query object. | ||
| * @return bool True to preempt 404 handling if a valid sitemap route is requested, original $preempt otherwise. | ||
| */ | ||
| public function prevent_sitemap_404( $preempt, $query ) { |
There was a problem hiding this comment.
| public function prevent_sitemap_404( $preempt, $query ) { | |
| public function prevent_sitemap_404( $preempt, WP_Query $query ): bool { |
I'm specifically not adding a type hint to $preempt because other plugins could provide something non-bool and cause a fatal error.
| if ( $query->is_main_query() && get_query_var( 'sitemap' ) ) { | ||
| if ( $this->sitemaps_enabled() ) { | ||
| return true; | ||
| } | ||
| } |
There was a problem hiding this comment.
This can be simplified:
| if ( $query->is_main_query() && get_query_var( 'sitemap' ) ) { | |
| if ( $this->sitemaps_enabled() ) { | |
| return true; | |
| } | |
| } | |
| if ( | |
| $query->is_main_query() && | |
| get_query_var( 'sitemap' ) && | |
| $this->sitemaps_enabled() | |
| ) { | |
| return true; | |
| } |
| * | ||
| * @link https://developers.google.com/web/updates/2014/11/Support-for-theme-color-in-Chrome-39-for-Android | ||
| * @link https://developer.chrome.com/multidevice/android/installtohomescreen | ||
| * @link https://developer.chrome.com/blog/support-for-theme-color-in-chrome-39-for-android |
There was a problem hiding this comment.
These are unrelated changes which could be opened in a separate PR for Core-65860.
|
Closing in favor of #13247. Thanks! |
https://core.trac.wordpress.org/ticket/65936
Trac ticket:
Use of AI Tools
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.