diff --git a/src/wp-includes/sitemaps/providers/class-wp-sitemaps-users.php b/src/wp-includes/sitemaps/providers/class-wp-sitemaps-users.php index a241f2468e..8e9f57dc6c 100644 --- a/src/wp-includes/sitemaps/providers/class-wp-sitemaps-users.php +++ b/src/wp-includes/sitemaps/providers/class-wp-sitemaps-users.php @@ -136,8 +136,9 @@ class WP_Sitemaps_Users extends WP_Sitemaps_Provider { ) ); - // We're not supporting sitemaps for author pages for attachments. + // We're not supporting sitemaps for author pages for attachments and pages. unset( $public_post_types['attachment'] ); + unset( $public_post_types['page'] ); /** * Filters the query arguments for authors with public posts. diff --git a/tests/phpunit/tests/sitemaps/wpSitemapsUsers.php b/tests/phpunit/tests/sitemaps/wpSitemapsUsers.php index d52e191835..eae9c03b27 100644 --- a/tests/phpunit/tests/sitemaps/wpSitemapsUsers.php +++ b/tests/phpunit/tests/sitemaps/wpSitemapsUsers.php @@ -2,6 +2,8 @@ /** * @group sitemaps + * + * @coversDefaultClass WP_Sitemaps_Users */ class Tests_Sitemaps_wpSitemapsUsers extends WP_UnitTestCase { @@ -10,14 +12,14 @@ class Tests_Sitemaps_wpSitemapsUsers extends WP_UnitTestCase { * * @var array */ - public static $users; + private static $users; /** * Editor ID for use in some tests. * * @var int */ - public static $editor_id; + private static $editor_id; /** * Set up fixtures. @@ -32,6 +34,8 @@ class Tests_Sitemaps_wpSitemapsUsers extends WP_UnitTestCase { /** * Test getting a URL list for a users sitemap page via * WP_Sitemaps_Users::get_url_list(). + * + * @covers ::get_url_list */ public function test_get_url_list_users() { // Set up the user to an editor to assign posts to other users. @@ -40,7 +44,7 @@ class Tests_Sitemaps_wpSitemapsUsers extends WP_UnitTestCase { // Create a set of posts for each user and generate the expected URL list data. $expected = array_map( static function ( $user_id ) { - $post = self::factory()->post->create_and_get( array( 'post_author' => $user_id ) ); + self::factory()->post->create( array( 'post_author' => $user_id ) ); return array( 'loc' => get_author_posts_url( $user_id ), @@ -55,4 +59,34 @@ class Tests_Sitemaps_wpSitemapsUsers extends WP_UnitTestCase { $this->assertSameSets( $expected, $url_list ); } + + /** + * @covers ::get_url_list + * @covers ::get_users_query_args + */ + public function test_get_url_list_skips_users_with_only_attachments_and_pages() { + // Set up the user to an editor to assign posts to other users. + wp_set_current_user( self::$editor_id ); + + foreach ( self::$users as $user_id ) { + self::factory()->post->create( + array( + 'post_author' => $user_id, + 'post_type' => 'attachment', + ) + ); + self::factory()->post->create( + array( + 'post_author' => $user_id, + 'post_type' => 'page', + ) + ); + } + + $user_provider = new WP_Sitemaps_Users(); + + $url_list = $user_provider->get_url_list( 1 ); + + $this->assertEmpty( $url_list ); + } }