mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@56708 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user