Ticket #23498: 23498.6.diff
File 23498.6.diff, 3.7 KB (added by , 5 years ago) |
---|
-
src/wp-includes/author-template.php
379 379 * @link https://developer.wordpress.org/reference/functions/wp_list_authors/ 380 380 * 381 381 * @since 1.2.0 382 * @since 5.3.0 The `$exclude_admin` parameter was updated to exclude all administrators. 382 383 * 383 384 * @global wpdb $wpdb WordPress database abstraction object. 384 385 * … … 391 392 * @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'. 392 393 * @type int $number Maximum authors to return or display. Default empty (all authors). 393 394 * @type bool $optioncount Show the count in parenthesis next to the author's name. Default false. 394 * @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default true.395 * @type bool $exclude_admin Whether to exclude administrator accounts. Default true. 395 396 * @type bool $show_fullname Whether to show the author's full name. Default false. 396 397 * @type bool $hide_empty Whether to hide any authors with no posts. Default true. 397 398 * @type string $feed If not empty, show a link to the author's feed and use this text as the alt … … 434 435 435 436 $return = ''; 436 437 437 $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); 438 $query_args['fields'] = 'ids'; 439 $authors = get_users( $query_args ); 438 $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) ); 440 439 440 $query_args['fields'] = 'ID'; 441 442 if ( $args['exclude_admin'] ) { 443 $query_args['exclude'] = get_users( array( 444 'role' => 'administrator', 445 'fields' => 'ID', 446 ) ); 447 } 448 449 $authors = get_users( $query_args ); 450 441 451 $author_count = array(); 442 452 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 453 $author_count[ $row->post_author ] = $row->count; … … 451 461 452 462 $author = get_userdata( $author_id ); 453 463 454 if ( $args['exclude_admin'] && 'admin' === $author->display_name ) {455 continue;456 }457 458 464 if ( $args['show_fullname'] && $author->first_name && $author->last_name ) { 459 465 $name = "$author->first_name $author->last_name"; 460 466 } else { -
tests/phpunit/tests/user/listAuthors.php
51 51 'last_name' => 'norris', 52 52 ) 53 53 ); 54 self::$user_ids[] = $factory->user->create( 55 array( 56 'user_login' => 'mary', 57 'display_name' => 'mary', 58 'role' => 'administrator', 59 'first_name' => 'mary', 60 'last_name' => 'strong', 61 ) 62 ); 54 63 self::$fred_id = $factory->user->create( 55 64 array( 56 65 'user_login' => 'fred', … … 135 144 ); 136 145 } 137 146 147 /** 148 * @ticket 23498 149 */ 138 150 function test_wp_list_authors_exclude_admin() { 139 151 self::factory()->post->create( 140 152 array( … … 146 158 $expected['exclude_admin'] = 147 159 '<li><a href="' . get_author_posts_url( 1 ) . '" title="Posts by admin">admin</a></li>' . 148 160 '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' . 161 '<li><a href="' . self::$user_urls[3] . '" title="Posts by mary">mary</a></li>' . 149 162 '<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' . 150 163 '<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>'; 151 164