Make WordPress Core

Ticket #63004: 63004.3.patch

File 63004.3.patch, 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..71dd25efd5 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-circuit counting of users' posts.
     665         *
     666         * @since 6.8.0
     667         *
     668         * @param bool $skip_count Whether to skip counting the users' posts.
     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        $userlist = implode( ',', wp_parse_id_list( $users ) );
    669679        $where    = get_posts_by_author_sql( $post_type, true, null, $public_only );
    670680
    671681        $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
     682
     683        $count = array_fill_keys( $userlist, 0 );
    672684        foreach ( $result as $row ) {
    673685                $count[ $row[0] ] = $row[1];
    674686        }
    675687
    676         foreach ( $users as $id ) {
    677                 if ( ! isset( $count[ $id ] ) ) {
    678                         $count[ $id ] = 0;
    679                 }
    680         }
    681 
    682688        return $count;
    683689}
    684690