From 4a237f2d4806cf34709d28482baba85e2435dadd Mon Sep 17 00:00:00 2001 From: whyisjake Date: Thu, 16 Jul 2020 21:44:04 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@48497 git-svn-id: http://core.svn.wordpress.org/trunk@48259 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 7 +++++++ wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 097f8186e9..20c4d4da42 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2647,6 +2647,13 @@ function wp_count_posts( $type = 'post', $perm = '' ) { $counts = wp_cache_get( $cache_key, 'counts' ); if ( false !== $counts ) { + // We may have cached this before every status was registered. + foreach ( get_post_stati() as $status ) { + if ( ! isset( $counts->{$status} ) ) { + $counts->{$status} = 0; + } + } + /** This filter is documented in wp-includes/post.php */ return apply_filters( 'wp_count_posts', $counts, $type, $perm ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index df9ef47882..416fa8f053 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-beta2-48496'; +$wp_version = '5.5-beta2-48497'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.