| 1 | Index: src/wp-includes/user.php
|
|---|
| 2 | ===================================================================
|
|---|
| 3 | --- src/wp-includes/user.php (revision 60000)
|
|---|
| 4 | +++ src/wp-includes/user.php (working copy)
|
|---|
| 5 | @@
|
|---|
| 6 | function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) {
|
|---|
| 7 | global $wpdb;
|
|---|
| 8 |
|
|---|
| 9 | if ( empty( $users ) || ! is_array( $users ) ) {
|
|---|
| 10 | return array();
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | + $cache_key = 'count_many_users_posts:' . md5( maybe_serialize( $users ) . '|' . $post_type . '|' . ( $public_only ? '1' : '0' ) );
|
|---|
| 14 | + $cached = wp_cache_get( $cache_key, 'counts' );
|
|---|
| 15 | + if ( false !== $cached ) {
|
|---|
| 16 | + return $cached;
|
|---|
| 17 | + }
|
|---|
| 18 | +
|
|---|
| 19 | $users = array_map( 'intval', $users );
|
|---|
| 20 |
|
|---|
| 21 | $where = get_posts_by_author_sql( $post_type, true, $users, $public_only );
|
|---|
| 22 | $where = preg_replace( '/^\s*AND\s*/', '', $where );
|
|---|
| 23 |
|
|---|
| 24 | $userlist = implode( ',', $users );
|
|---|
| 25 |
|
|---|
| 26 | $count = $wpdb->get_results( "SELECT post_author, COUNT(*) AS post_count FROM $wpdb->posts WHERE $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_A );
|
|---|
| 27 |
|
|---|
| 28 | $counts = array_fill_keys( $users, 0 );
|
|---|
| 29 | foreach ( $count as $row ) {
|
|---|
| 30 | $counts[ $row['post_author'] ] = (int) $row['post_count'];
|
|---|
| 31 | }
|
|---|
| 32 | +
|
|---|
| 33 | + wp_cache_set( $cache_key, $counts, 'counts' );
|
|---|
| 34 |
|
|---|
| 35 | return $counts;
|
|---|
| 36 | }
|
|---|