Skip to content

Commit

Permalink
Fix crash when crawling sitemaps
Browse files Browse the repository at this point in the history
Fixes #751, #781, #798.

Co-authored-by: John Shaffer <jshaffer2112@protonmail.com>
  • Loading branch information
palmiak and john-shaffer committed Sep 5, 2021
1 parent 2d7cc36 commit 59540b1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/DetectSitemapsURLs.php
Expand Up @@ -83,9 +83,9 @@ public static function detect( string $wp_site_url ) : array {
if ( $sitemaps === [] ) {
$sitemaps = [
// we're assigning empty arrays to match sitemaps library
'/sitemap.xml' => [], // normal sitemap
'/sitemap_index.xml' => [], // yoast sitemap
'/wp-sitemap.xml' => [], // default WordPress sitemap
'sitemap.xml' => [], // normal sitemap
'sitemap_index.xml' => [], // yoast sitemap
'wp-sitemap.xml' => [], // default WordPress sitemap
];
}

Expand All @@ -94,20 +94,22 @@ public static function detect( string $wp_site_url ) : array {
continue;
}

$sitemap = '/' . str_replace(
$wp_site_url,
'',
$sitemap
);

$request = new Request( 'GET', $sitemap, $headers );

$response = $client->send( $request );

$status_code = $response->getStatusCode();

if ( $status_code === 200 ) {
$parser->parse( $wp_site_url . $sitemap );
$sitemap_urls[] = $sitemap;

$sitemaps_urls[] = '/' . str_replace(
$wp_site_url,
'',
$sitemap
);
$parser->parse( $wp_site_url . $sitemap );

$extract_sitemaps = $parser->getSitemaps();

Expand Down

0 comments on commit 59540b1

Please sign in to comment.