diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php
index 2646fb94c3..d7b649e769 100644
|
a
|
b
|
function wp_list_authors( $args = '' ) {
|
| 428 | 428 | 'html' => true, |
| 429 | 429 | 'exclude' => '', |
| 430 | 430 | 'include' => '', |
| | 431 | 'role' => '', |
| | 432 | 'role__in' => array(), |
| | 433 | 'role__not_in' => array(), |
| 431 | 434 | ); |
| 432 | 435 | |
| 433 | 436 | $args = wp_parse_args( $args, $defaults ); |
| 434 | 437 | |
| 435 | 438 | $return = ''; |
| 436 | 439 | |
| 437 | | $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); |
| 438 | | $query_args['fields'] = 'ids'; |
| | 440 | $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include', 'role', 'role__in', 'role__not_in' ) ); |
| 439 | 441 | $authors = get_users( $query_args ); |
| 440 | 442 | |
| 441 | 443 | $author_count = array(); |
| 442 | 444 | foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE " . get_private_posts_cap_sql( 'post' ) . ' GROUP BY post_author' ) as $row ) { |
| 443 | 445 | $author_count[ $row->post_author ] = $row->count; |
| 444 | 446 | } |
| 445 | | foreach ( $authors as $author_id ) { |
| 446 | | $posts = isset( $author_count[ $author_id ] ) ? $author_count[ $author_id ] : 0; |
| | 447 | foreach ( $authors as $author ) { |
| | 448 | $posts = isset( $author_count[ $author->ID ] ) ? $author_count[ $author->ID ] : 0; |
| 447 | 449 | |
| 448 | 450 | if ( ! $posts && $args['hide_empty'] ) { |
| 449 | 451 | continue; |
| 450 | 452 | } |
| 451 | 453 | |
| 452 | | $author = get_userdata( $author_id ); |
| 453 | | |
| 454 | 454 | if ( $args['exclude_admin'] && 'admin' === $author->display_name ) { |
| 455 | 455 | continue; |
| 456 | 456 | } |
diff --git a/tests/phpunit/tests/user/listAuthors.php b/tests/phpunit/tests/user/listAuthors.php
index ccaa733551..8869d66186 100644
|
a
|
b
|
class Tests_User_ListAuthors extends WP_UnitTestCase {
|
| 304 | 304 | ) |
| 305 | 305 | ); |
| 306 | 306 | } |
| | 307 | |
| | 308 | function test_wp_list_authors_role() { |
| | 309 | $expected['role'] = ''; |
| | 310 | |
| | 311 | $this->assertEquals( |
| | 312 | $expected['role'], |
| | 313 | wp_list_authors( |
| | 314 | array( |
| | 315 | 'echo' => false, |
| | 316 | 'role' => 'administrator', |
| | 317 | ) |
| | 318 | ) |
| | 319 | ); |
| | 320 | } |
| | 321 | |
| | 322 | function test_wp_list_authors_role__in() { |
| | 323 | $expected['role__in'] = ''; |
| | 324 | |
| | 325 | $this->assertEquals( |
| | 326 | $expected['role__in'], |
| | 327 | wp_list_authors( |
| | 328 | array( |
| | 329 | 'echo' => false, |
| | 330 | 'role__in' => [ 'administrator', 'editor' ], |
| | 331 | ) |
| | 332 | ) |
| | 333 | ); |
| | 334 | } |
| | 335 | |
| | 336 | function test_wp_list_authors_role__not_in() { |
| | 337 | $expected['role__not_in'] = |
| | 338 | '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' . |
| | 339 | '<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' . |
| | 340 | '<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>'; |
| | 341 | |
| | 342 | $this->assertEquals( |
| | 343 | $expected['role__not_in'], |
| | 344 | wp_list_authors( |
| | 345 | array( |
| | 346 | 'echo' => false, |
| | 347 | 'role__not_in' => [ 'administrator', 'editor' ], |
| | 348 | ) |
| | 349 | ) |
| | 350 | ); |
| | 351 | } |
| 307 | 352 | } |