Make WordPress Core

Ticket #63004: GH-8410.diff

File GH-8410.diff, 1.3 KB (added by jigar bhanushali, 9 months ago)
  • src/wp-includes/user.php

    diff --git a/src/wp-includes/user.php b/src/wp-includes/user.php
    index fe6f185680..56b63bd290 100644
    a b function count_user_posts( $userid, $post_type = 'post', $public_only = false ) 
    660660function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) {
    661661        global $wpdb;
    662662
    663         $count = array();
     663        /**
     664         * Short-circuits counting of users' posts.
     665         *
     666         * @since 6.8.0
     667         *
     668         * @param bool $skip_count Whether to skip counting the users' posts. Default false.
     669         */
     670        if ( apply_filters( 'skip_count_many_users_posts', false ) ) {
     671                return array();
     672        }
     673
    664674        if ( empty( $users ) || ! is_array( $users ) ) {
    665                 return $count;
     675                return array();
    666676        }
    667677
    668         $userlist = implode( ',', array_map( 'absint', $users ) );
     678        $users    = wp_parse_id_list( $users );
     679        $userlist = implode( ',', $users );
    669680        $where    = get_posts_by_author_sql( $post_type, true, null, $public_only );
    670681
    671682        $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
     683
     684        $count = array_fill_keys( $users, 0 );
    672685        foreach ( $result as $row ) {
    673686                $count[ $row[0] ] = $row[1];
    674687        }
    675688
    676         foreach ( $users as $id ) {
    677                 if ( ! isset( $count[ $id ] ) ) {
    678                         $count[ $id ] = 0;
    679                 }
    680         }
    681 
    682689        return $count;
    683690}
    684691