Make WordPress Core

Ticket #23498: 23498.4.diff

File 23498.4.diff, 2.1 KB (added by donmhico, 5 years ago)

Refreshed the patch for 5.3.

  • src/wp-includes/author-template.php

    diff --git src/wp-includes/author-template.php src/wp-includes/author-template.php
    index 4ee210f555..e9dbf4ecd6 100644
    function wp_list_authors( $args = '' ) { 
    435435
    436436        $query_args           = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
    437437        $query_args['fields'] = 'ids';
    438         $authors              = get_users( $query_args );
     438
     439        // @link https://core.trac.wordpress.org/ticket/23498
     440        if( true == $args['exclude_admin'] ) {
     441                $exclude = get_users( array( 'role' => 'administrator' ) );
     442                foreach ( $exclude as $admin ) {
     443                        $exclude_ids[] = $admin->ID;
     444                }
     445                $query_args['exclude'] = $exclude_ids;
     446        }
     447
     448        $authors = get_users( $query_args );
    439449
    440450        $author_count = array();
    441451        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 ) {
    function wp_list_authors( $args = '' ) { 
    450460
    451461                $author = get_userdata( $author_id );
    452462
    453                 if ( $args['exclude_admin'] && 'admin' === $author->display_name ) {
    454                         continue;
    455                 }
    456 
    457463                if ( $args['show_fullname'] && $author->first_name && $author->last_name ) {
    458464                        $name = "$author->first_name $author->last_name";
    459465                } else {
  • tests/phpunit/tests/user/listAuthors.php

    diff --git tests/phpunit/tests/user/listAuthors.php tests/phpunit/tests/user/listAuthors.php
    index 8dcfad8935..216b3b9db6 100644
    class Tests_User_ListAuthors extends WP_UnitTestCase { 
    248248                        )
    249249                );
    250250        }
     251
     252        /**
     253         * @ticket 23498
     254         **/
     255        function test_wp_list_authors_number() {
     256                $expected['number'] =
     257                        '<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' .
     258                        '<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' .
     259                        '<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
     260                $a = wp_list_authors( array( 'echo' => false ) );
     261                $this->AssertEquals( $expected['number'], $a );
     262        }
     263
    251264}