Make WordPress Core

Changeset 56708


Ignore:
Timestamp:
09/26/2023 12:40:36 PM (10 months ago)
Author:
swissspidy
Message:

Sitemaps: do not list users who only authored pages.

Author archives are only generated for users who created at least one post.
Prevent adding author archives to the XML sitemap for users who only authored pages
as the links would otherwise result in a 404.

Props zodiac1978, huzaifaalmesbah.
Fixes #57816.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/sitemaps/providers/class-wp-sitemaps-users.php

    r52422 r56708  
    137137        );
    138138
    139         // We're not supporting sitemaps for author pages for attachments.
     139        // We're not supporting sitemaps for author pages for attachments and pages.
    140140        unset( $public_post_types['attachment'] );
     141        unset( $public_post_types['page'] );
    141142
    142143        /**
  • trunk/tests/phpunit/tests/sitemaps/wpSitemapsUsers.php

    r51492 r56708  
    33/**
    44 * @group sitemaps
     5 *
     6 * @coversDefaultClass WP_Sitemaps_Users
    57 */
    68class Tests_Sitemaps_wpSitemapsUsers extends WP_UnitTestCase {
     
    1113     * @var array
    1214     */
    13     public static $users;
     15    private static $users;
    1416
    1517    /**
     
    1820     * @var int
    1921     */
    20     public static $editor_id;
     22    private static $editor_id;
    2123
    2224    /**
     
    3335     * Test getting a URL list for a users sitemap page via
    3436     * WP_Sitemaps_Users::get_url_list().
     37     *
     38     * @covers ::get_url_list
    3539     */
    3640    public function test_get_url_list_users() {
     
    4145        $expected = array_map(
    4246            static function ( $user_id ) {
    43                 $post = self::factory()->post->create_and_get( array( 'post_author' => $user_id ) );
     47                self::factory()->post->create( array( 'post_author' => $user_id ) );
    4448
    4549                return array(
     
    5660        $this->assertSameSets( $expected, $url_list );
    5761    }
     62
     63    /**
     64     * @covers ::get_url_list
     65     * @covers ::get_users_query_args
     66     */
     67    public function test_get_url_list_skips_users_with_only_attachments_and_pages() {
     68        // Set up the user to an editor to assign posts to other users.
     69        wp_set_current_user( self::$editor_id );
     70
     71        foreach ( self::$users as $user_id ) {
     72            self::factory()->post->create(
     73                array(
     74                    'post_author' => $user_id,
     75                    'post_type'   => 'attachment',
     76                )
     77            );
     78            self::factory()->post->create(
     79                array(
     80                    'post_author' => $user_id,
     81                    'post_type'   => 'page',
     82                )
     83            );
     84        }
     85
     86        $user_provider = new WP_Sitemaps_Users();
     87
     88        $url_list = $user_provider->get_url_list( 1 );
     89
     90        $this->assertEmpty( $url_list );
     91    }
    5892}
Note: See TracChangeset for help on using the changeset viewer.