Make WordPress Core


Ignore:
Timestamp:
07/16/2020 09:42:48 PM (6 years 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/src/wp-includes/post.php

    r48480 r48497  
    26482648        $counts = wp_cache_get( $cache_key, 'counts' );
    26492649        if ( false !== $counts ) {
     2650                // We may have cached this before every status was registered.
     2651                foreach ( get_post_stati() as $status ) {
     2652                        if ( ! isset( $counts->{$status} ) ) {
     2653                                $counts->{$status} = 0;
     2654                        }
     2655                }
     2656
    26502657                /** This filter is documented in wp-includes/post.php */
    26512658                return apply_filters( 'wp_count_posts', $counts, $type, $perm );
Note: See TracChangeset for help on using the changeset viewer.