diff --git a/projects/plugins/jetpack/changelog/sitemap-consider-other-urls-lastmod b/projects/plugins/jetpack/changelog/sitemap-consider-other-urls-lastmod new file mode 100644 index 0000000000000..908b5fce6df69 --- /dev/null +++ b/projects/plugins/jetpack/changelog/sitemap-consider-other-urls-lastmod @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Sitemaps: Ensured that the last modification date from the jetpack_page_sitemap_other_urls filter is considered for the last modification date of the generated sitemap. diff --git a/projects/plugins/jetpack/modules/sitemaps/sitemap-builder.php b/projects/plugins/jetpack/modules/sitemaps/sitemap-builder.php index 90d4571dd578c..a524af7d7a8af 100644 --- a/projects/plugins/jetpack/modules/sitemaps/sitemap-builder.php +++ b/projects/plugins/jetpack/modules/sitemaps/sitemap-builder.php @@ -686,6 +686,9 @@ public function build_one_page_sitemap( $number, $from_id ) { if ( true === $buffer->append( $item['xml'] ) ) { $last_post_id = -$index; + if ( isset( $url['lastmod'] ) ) { + $buffer->view_time( jp_sitemap_datetime( $url['lastmod'] ) ); + } } else { break; } diff --git a/projects/plugins/jetpack/tests/php/modules/sitemaps/test-class.sitemap-builder.php b/projects/plugins/jetpack/tests/php/modules/sitemaps/test-class.sitemap-builder.php new file mode 100644 index 0000000000000..46e948e114705 --- /dev/null +++ b/projects/plugins/jetpack/tests/php/modules/sitemaps/test-class.sitemap-builder.php @@ -0,0 +1,52 @@ + 'https://example.com/1', + 'lastmod' => '2019-01-01T00:00:00Z', + ), + array( + 'loc' => 'https://example.com/2', + 'lastmod' => '2024-03-08T01:02:03Z', + ), + array( + 'loc' => 'https://example.com/3', + 'lastmod' => '2022-02-02T00:00:00Z', + ), + ); + + $callback = function () use ( $other_urls ) { + return $other_urls; + }; + + add_filter( 'jetpack_page_sitemap_other_urls', $callback ); + + $builder = new Jetpack_Sitemap_Builder(); + $result = $builder->build_one_page_sitemap( 1, 1 ); + + remove_filter( 'jetpack_page_sitemap_other_urls', $callback ); + + $this->assertSame( '2024-03-08T01:02:03Z', $result['last_modified'], 'Last modified date is not the one from the other_urls filter.' ); + } +}