-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Fix: Core sitemaps rendered with HTTP 404 status when no post. #13240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
03ba987
336ff55
f13c964
d3bf6e8
22e1af0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,6 +76,7 @@ public function init() { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // Add additional action callbacks. | ||||||||||||||||||||||||||
| add_filter( 'robots_txt', array( $this, 'add_robots' ), 0, 2 ); | ||||||||||||||||||||||||||
| add_filter( 'pre_handle_404', array( $this, 'prevent_sitemap_404' ), 10, 2 ); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
|
|
@@ -263,4 +264,24 @@ public function add_robots( $output, $is_public ) { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return $output; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Prevents core from issuing a 404 status header on valid sitemap requests | ||||||||||||||||||||||||||
| * when no standard blog posts exist. | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @since 7.1.1 | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @param bool $preempt Whether to short-circuit default 404 handling. | ||||||||||||||||||||||||||
| * @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 ) { | ||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I'm specifically not adding a type hint to |
||||||||||||||||||||||||||
| if ( $query->is_main_query() && get_query_var( 'sitemap' ) ) { | ||||||||||||||||||||||||||
| if ( $this->sitemaps_enabled() ) { | ||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+279
to
+283
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be simplified:
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return $preempt; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are unrelated changes which could be opened in a separate PR for Core-65860.