Make WordPress Core

Ticket #17025: 17025.8.diff

File 17025.8.diff, 1.5 KB (added by audrasjb, 3 years ago)

Query: introduce a new hook to filter wp_list_authors

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

    diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php
    index 2911366f03..6665c4d65d 100644
    a b function wp_list_authors( $args = '' ) { 
    437437
    438438        $query_args           = wp_array_slice_assoc( $args, array( 'orderby', 'order', 'number', 'exclude', 'include' ) );
    439439        $query_args['fields'] = 'ids';
    440         $authors              = get_users( $query_args );
    441440
    442441        $author_count = array();
    443         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 ) {
     442        $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' );
     443        foreach ( $rows as $row ) {
    444444                $author_count[ $row->post_author ] = $row->count;
    445445        }
     446
     447        if ( $args['hide_empty'] ) {
     448                $query_args['include'] = wp_list_pluck( $rows, 'post_author' );
     449        } else {
     450                $query_args['fields'] = 'ids';
     451        }
     452
     453        /**
     454         * Filters the list of authors.
     455         *
     456         * @since 5.9.0
     457         *
     458         * @param array $authors    Array of WP_User objects for found authors.
     459         * @param array $query_args User query arguments.
     460         */
     461        $authors = apply_filters( 'wp_list_authors', get_users( $query_args ), $query_args );
     462
    446463        foreach ( $authors as $author_id ) {
    447464                $posts = isset( $author_count[ $author_id ] ) ? $author_count[ $author_id ] : 0;
    448465