Make WordPress Core

Ticket #63004: 63004.5.patch

File 63004.5.patch, 1.7 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..eda87e21b5 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();
    664663        if ( empty( $users ) || ! is_array( $users ) ) {
    665                 return $count;
     664                return array();
     665        }
     666
     667        /**
     668         * Filters whether to short-circuit performing the post counts.
     669         *
     670         * When filtering, return an array of posts counts as strings, keyed
     671         * by the user ID.
     672         *
     673         * @since 6.8.0
     674         *
     675         * @param string[]|null   $count       The post counts. Return a non-null value to short-circuit.
     676         * @param int[]           $users       Array of user IDs.
     677         * @param string|string[] $post_type   Single post type or array of post types to check.
     678         * @param bool            $public_only Whether to only return counts for public posts.
     679         */
     680        $pre = apply_filters( 'pre_count_many_users_posts', null, $users, $post_type, $public_only );
     681        if ( null !== $pre ) {
     682                return $pre;
    666683        }
    667684
    668         $userlist = implode( ',', array_map( 'absint', $users ) );
     685        $users    = wp_parse_id_list( $users );
     686        $userlist = implode( ',', $users );
    669687        $where    = get_posts_by_author_sql( $post_type, true, null, $public_only );
    670688
    671689        $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
     690
     691        $count = array_fill_keys( $users, 0 );
    672692        foreach ( $result as $row ) {
    673693                $count[ $row[0] ] = $row[1];
    674694        }
    675695
    676         foreach ( $users as $id ) {
    677                 if ( ! isset( $count[ $id ] ) ) {
    678                         $count[ $id ] = 0;
    679                 }
    680         }
    681 
    682696        return $count;
    683697}
    684698