Skip to content

Commit

Permalink
Ensured that the last modification date from the jetpack_page_sitema…
Browse files Browse the repository at this point in the history
…p_other_urls filter is considered for the last modification date of the generated sitemap. (#36991)
  • Loading branch information
ArSn authored Apr 19, 2024
1 parent c0fe6d8 commit 7e20e6c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions projects/plugins/jetpack/modules/sitemaps/sitemap-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Tests for the Jetpack_Sitemap_Builder class.
*
* @package automattic/jetpack
* @since $$next-version$$
*/

/**
* Test class for Jetpack_Sitemap_Builder.
*
* @since $$next-version$$
*/
class WP_Test_Jetpack_Sitemap_Builder extends WP_UnitTestCase {

/**
* "lastmod" date from other URLs filter is considered when building a sitemap.
*
* @covers Jetpack_Sitemap_Builder::build_one_page_sitemap
* @group jetpack-sitemap
* @since $$next-version$$
*/
public function test_build_one_page_sitemap_considers_lastmod_from_other_urls() {
$other_urls = array(
array(
'loc' => '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.' );
}
}

0 comments on commit 7e20e6c

Please sign in to comment.