Skip to content
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

Fix: force a 404 if no provider is found #8085

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/wp-includes/sitemaps/class-wp-sitemaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ public function render_sitemaps() {

$provider = $this->registry->get_provider( $sitemap );

// Force a 404 and bail early if no provider is present.
if ( ! $provider ) {
$wp_query->set_404();
status_header( 404 );
return;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/tests/sitemaps/sitemaps.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,17 @@ public function test_empty_url_list_should_return_404() {

$this->assertTrue( is_404() );
}

/**
* @ticket 62777
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_unknown_provider_should_return_404() {
$this->go_to( home_url( '/?sitemap=foo' ) );

wp_sitemaps_get_server()->render_sitemaps();

$this->assertTrue( is_404() );
}
}
Loading