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 ) |
| 660 | 660 | function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
| 661 | 661 | global $wpdb; |
| 662 | 662 | |
| 663 | | $count = array(); |
| 664 | 663 | 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; |
| 666 | 683 | } |
| 667 | 684 | |
| 668 | | $userlist = implode( ',', array_map( 'absint', $users ) ); |
| | 685 | $users = wp_parse_id_list( $users ); |
| | 686 | $userlist = implode( ',', $users ); |
| 669 | 687 | $where = get_posts_by_author_sql( $post_type, true, null, $public_only ); |
| 670 | 688 | |
| 671 | 689 | $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 ); |
| 672 | 692 | foreach ( $result as $row ) { |
| 673 | 693 | $count[ $row[0] ] = $row[1]; |
| 674 | 694 | } |
| 675 | 695 | |
| 676 | | foreach ( $users as $id ) { |
| 677 | | if ( ! isset( $count[ $id ] ) ) { |
| 678 | | $count[ $id ] = 0; |
| 679 | | } |
| 680 | | } |
| 681 | | |
| 682 | 696 | return $count; |
| 683 | 697 | } |
| 684 | 698 | |