Make WordPress Core

Changeset 55444

Timestamp:
03/01/2023 03:37:06 PM (17 months ago)
Author:
SergeyBiryukov
Message:

Users: Use a separate variable for the post counts query in wp_list_authors().

This avoids a collision if wp_list_authors() is called with the optioncount parameter enabled, and the resulting array for the post counts query contains a key that matches the ID of a user who does not have any posts.

Follow-up to [54262].

Props peterwilsoncc, johnbillion, lifeboat, brookedot, thedaysse, Toru.
Fixes #57011.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/author-template.php

    r55398 r55444  
    482482
    483483    if ( ! is_array( $post_counts ) ) {
    484         $post_counts = $wpdb->get_results(
     484        $post_counts       = array();
     485        $post_counts_query = $wpdb->get_results(
    485486            "SELECT DISTINCT post_author, COUNT(ID) AS count
    486487            FROM $wpdb->posts
     
    489490        );
    490491
    491         foreach ( (array) $post_counts as $row ) {
     492        foreach ( (array) $post_counts as $row ) {
    492493            $post_counts[ $row->post_author ] = $row->count;
    493494        }
  • trunk/tests/phpunit/tests/user/wpListAuthors.php

    r53488 r55444  
    147147    }
    148148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
    149174    public function test_wp_list_authors_exclude_admin() {
    150175        self::factory()->post->create(
Note: See TracChangeset for help on using the changeset viewer.