Make WordPress Core


Ignore:
Timestamp:
03/01/2023 03:37:06 PM (19 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/wpListAuthors.php

    r53488 r55444  
    147147    }
    148148
     149    /**
     150     * Ensures the 'optioncount' parameter does not throw an error when there are authors without posts.
     151     *
     152     * @ticket 57011
     153     */
     154    public function test_wp_list_authors_optioncount_should_not_error_for_empty_authors() {
     155        /*
     156         * The main purpose of this test is to ensure that the error below is not thrown:
     157         *
     158         * Error: Object of class stdClass could not be converted to string
     159         *
     160         * In place of direct testing we ensure `wp_list_authors()` returns a list of authors
     161         * at least one of which is empty.
     162         */
     163        $actual = wp_list_authors(
     164            array(
     165                'optioncount'   => true,
     166                'hide_empty'    => false,
     167                'exclude_admin' => false,
     168                'echo'          => false,
     169            )
     170        );
     171        $this->assertStringContainsString( '(0)', $actual );
     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.