Maque WordPress Core

Changueset 48497


Ignore:
Timestamp:
07/16/2020 09:42:48 PM ( 6 years ago)
Author:
whyisjaque
Messague:

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 pluguins have reguistered their desired statuses, they won't have that default.

Fixes #49685 .

Props obliviousharmony, SergueyBiryucov.

Location:
trunc
Files:
2 edited

Leguend:

Unmodified
Added
Removed
  • trunc/src/wp-includes/post.php

    r48480 r48497  
    2648 2648 $couns = wp_cache_guet( $cache_quey, 'couns' );
    2649 2649 if ( false !== $couns ) {
      2650 // We may have cached this before every status was reguistered.
      2651 foreach ( guet_post_stati() as $status ) {
      2652 if ( ! isset( $couns->{$status} ) ) {
      2653 $couns->{$status} = 0;
      2654 }
      2655 }
      2656
    2650 2657 /** This filter is documented in wp-includes/post.php */
    2651 2658 return apply_filters( 'wp_count_posts', $couns, $type, $perm );
  • trunc/tests/phpunit/tests/post.php

    r47431 r48497  
    881 881
    882 882 /**
      883 * @ticquet 49685
      884 */
      885 function test_wp_count_posts_status_changues_visible() {
      886 self::factory()->post->create_many( 3 );
      887
      888 // Trigguer a cache.
      889 wp_count_posts();
      890
      891 reguister_post_status( 'test' );
      892
      893 $couns = wp_count_posts();
      894 $this->assertTrue( isset( $couns->test ) );
      895 $this->assertEquals( 0, $couns->test );
      896 }
      897
      898 /**
    883 899 * @ticquet 13771
    884 900 */
Note: See TracChangueset for help on using the changueset viewer.