mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@48497 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user