Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions src/wp-admin/includes/class-wp-users-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public function get_columns() {
'name' => __( 'Name' ),
'email' => __( 'Email' ),
'role' => __( 'Role' ),
'posts' => _x( 'Posts', 'post type general name' ),
'posts' => _x( 'Content', 'users list table authored content column name' ),
);

if ( $this->is_site_users ) {
Expand Down Expand Up @@ -408,7 +408,7 @@ protected function get_sortable_columns() {
public function display_rows() {
// Query the post counts for this page.
if ( ! $this->is_site_users ) {
$post_counts = count_many_users_posts( array_keys( $this->items ) );
$post_counts = count_many_users_posts( array_keys( $this->items ), $this->get_countable_post_types() );
}

foreach ( $this->items as $userid => $user_object ) {
Expand Down Expand Up @@ -599,12 +599,11 @@ public function single_row( $user_object, $style = '', $role = '', $numposts = 0
case 'posts':
if ( $numposts > 0 ) {
$row .= sprintf(
'<a href="%s" class="edit"><span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
"edit.php?author={$user_object->ID}",
$numposts,
'<span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span>',
number_format_i18n( $numposts ),
sprintf(
/* translators: Hidden accessibility text. %s: Number of posts. */
_n( '%s post by this author', '%s posts by this author', $numposts ),
/* translators: Hidden accessibility text. %s: Number of content items. */
_n( '%s content item by this author', '%s content items by this author', $numposts ),
number_format_i18n( $numposts )
)
);
Expand Down Expand Up @@ -647,6 +646,33 @@ protected function get_default_primary_column_name() {
return 'username';
}

/**
* Returns the post types counted in the Users list table content column.
*
* Post types are limited to those with an admin UI that support authors, so the
* count reflects user-managed content such as posts, pages, media, and custom
* post types.
*
* @since 7.1.0
*
* @return string[] Post type names.
*/
protected function get_countable_post_types() {
return array_values(
array_filter(
get_post_types(
array(
'show_ui' => true,
),
'names'
),
static function ( $post_type ) {
return post_type_supports( $post_type, 'author' );
}
)
);
}

/**
* Returns an array of translated user role names for a given user object.
*
Expand Down
82 changes: 82 additions & 0 deletions tests/phpunit/tests/admin/wpUsersListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,86 @@ public function test_get_views_should_return_views_by_default() {

$this->assertSame( $expected, $this->table->get_views() );
}

/**
* @ticket 29128
*
* @covers WP_Users_List_Table::get_columns
*/
public function test_get_columns_should_label_posts_column_as_content() {
$columns = $this->table->get_columns();

$this->assertSame( 'Content', $columns['posts'] );
}

/**
* @ticket 29128
*
* @covers WP_Users_List_Table::display_rows
*/
public function test_display_rows_should_count_authored_content_items() {
register_post_type(
'book',
array(
'public' => true,
'show_ui' => true,
'supports' => array( 'title', 'author' ),
)
);

register_post_type(
'secret_note',
array(
'public' => true,
'show_ui' => false,
'supports' => array( 'title', 'author' ),
)
);

$user_id = self::factory()->user->create( array( 'role' => 'author' ) );

self::factory()->post->create(
array(
'post_author' => $user_id,
'post_type' => 'post',
)
);

self::factory()->post->create(
array(
'post_author' => $user_id,
'post_type' => 'page',
)
);

self::factory()->post->create(
array(
'post_author' => $user_id,
'post_type' => 'book',
)
);

self::factory()->post->create(
array(
'post_author' => $user_id,
'post_type' => 'secret_note',
)
);

try {
$this->table->items = array(
$user_id => get_userdata( $user_id ),
);

ob_start();
$this->table->display_rows();
$output = ob_get_clean();

$this->assertStringNotContainsString( 'edit.php?author=' . $user_id, $output );
$this->assertStringContainsString( '3 content items by this author', $output );
} finally {
unregister_post_type( 'book' );
unregister_post_type( 'secret_note' );
}
}
}
Loading