Make WordPress Core

Ticket #17025: 17025.4.diff

File 17025.4.diff, 1.7 KB (added by DrewAPicture, 12 years ago)

'ids' fallback for false $hide_empty

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

     
    334334        $return = '';
    335335
    336336        $query_args = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number' ) );
    337         $query_args['fields'] = 'ids';
    338         $authors = get_users( $query_args );
    339337
     338        $rows = $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author" );
     339
    340340        $author_count = array();
    341         foreach ( (array) $wpdb->get_results("SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' ) . " GROUP BY post_author") as $row )
     341        foreach ( (array) $rows as $row )
    342342                $author_count[$row->post_author] = $row->count;
    343343
    344         foreach ( $authors as $author_id ) {
    345                 $author = get_userdata( $author_id );
     344        if ( $hide_empty )
     345                $query_args['include'] = wp_list_pluck( $rows, 'post_author' );
     346        else
     347                $query_args['fields'] = 'ids';
    346348
     349        $authors = get_users( $query_args );
     350        /**
     351         * Filter the queried authors list.
     352         *
     353         * @since 3.7.0
     354         *
     355         * @param array $authors    An array of WP_User objects.
     356         * @param array $query_args An array of WP_User_Query arguments.
     357         * @param bool  $hide_empty Whether to exclude authors with no posts. Default true.
     358         */
     359        $authors = apply_filters( 'wp_list_authors', $authors, $query_args, $hide_empty );
     360
     361        foreach ( $authors as $author ) {
    347362                if ( $exclude_admin && 'admin' == $author->display_name )
    348363                        continue;
    349364