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
This commit is contained in:
whyisjake 2020-07-16 21:44:04 +00:00
parent 69aaab5108
commit 4a237f2d48
2 changed files with 8 additions and 1 deletions

View File

@ -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 );
}

View File

@ -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.