WordPress.org

Make WordPress Core

Ticket #18791: 18791.patch

File 18791.patch, 2.9 KB (added by mordauk, 5 years ago)
  • src/wp-includes/author-template.php

     
    336336                'orderby' => 'name', 'order' => 'ASC', 'number' => '',
    337337                'optioncount' => false, 'exclude_admin' => true,
    338338                'show_fullname' => false, 'hide_empty' => true,
    339                 'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true,
     339                'feed' => '', 'feed_image' => '', 'feed_type' => '', 'post_type' => '', 'echo' => true,
    340340                'style' => 'list', 'html' => true, 'exclude' => '', 'include' => ''
    341341        );
    342342
     
    348348        $query_args['fields'] = 'ids';
    349349        $authors = get_users( $query_args );
    350350
     351        if( ! empty( $args['post_type'] ) ) {
     352                $post_type = "post_type = '{$args['post_type']}' ";
     353        } else {
     354                $post_type = "";
     355        }
     356
    351357        $author_count = array();
    352         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 ) {
     358        foreach ( (array) $wpdb->get_results( "SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE $post_type" . get_private_posts_cap_sql( 'any' ) . " GROUP BY post_author" ) as $row ) {
    353359                $author_count[$row->post_author] = $row->count;
    354360        }
    355361        foreach ( $authors as $author_id ) {
     
    440446        global $wpdb;
    441447
    442448        if ( false === ( $is_multi_author = get_transient( 'is_multi_author' ) ) ) {
    443                 $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2");
     449                $rows = (array) $wpdb->get_col("SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status = 'publish' LIMIT 2");
    444450                $is_multi_author = 1 < count( $rows ) ? 1 : 0;
    445451                set_transient( 'is_multi_author', $is_multi_author );
    446452        }
  • src/wp-includes/post.php

     
    52385238                $cap = $post_type_obj->cap->read_private_posts;
    52395239        }
    52405240
    5241         if ( $full ) {
     5241        if ( $full && 'any' != $post_type ) {
    52425242                if ( null === $post_author ) {
    52435243                        $sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type );
    52445244                } else {
  • src/wp-includes/user.php

     
    256256 * @param int $userid User ID.
    257257 * @return int Amount of posts user has written.
    258258 */
    259 function count_user_posts($userid) {
     259function count_user_posts( $userid, $post_type = false ) {
    260260        global $wpdb;
    261261
    262         $where = get_posts_by_author_sql('post', true, $userid);
     262        $where = get_posts_by_author_sql( $post_type, true, $userid );
    263263
    264264        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    265265