WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/16/2020 09:42:48 PM (16 months ago)
Author:
whyisjake
Message:

Posts, Post Types: Ensure that all post stati are countable in wp_count_posts.

When wp_count_posts() is cached, it does so with all statuses defaulted to 0. The problem is however, if this is called before all plugins have registered their desired statuses, they won't have that default.

Fixes #49685.

Props obliviousharmony, SergeyBiryukov.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r47431 r48497  
    881881
    882882    /**
     883     * @ticket 49685
     884     */
     885    function test_wp_count_posts_status_changes_visible() {
     886        self::factory()->post->create_many( 3 );
     887
     888        // Trigger a cache.
     889        wp_count_posts();
     890
     891        register_post_status( 'test' );
     892
     893        $counts = wp_count_posts();
     894        $this->assertTrue( isset( $counts->test ) );
     895        $this->assertEquals( 0, $counts->test );
     896    }
     897
     898    /**
    883899     * @ticket 13771
    884900     */
Note: See TracChangeset for help on using the changeset viewer.