Make WordPress Core


Ignore:
Timestamp:
09/21/2013 05:54:36 PM (13 years ago)
Author:
wonderboymusic
Message:

Add hooks to wp_count_posts(). Adds filter docs. Adds unit test to test count_posts filter.

Props nacin, DrewAPicture.
Fixes #16603.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post.php

    r25265 r25554  
    809809        }
    810810
     811        function test_wp_count_posts_filtered() {
     812                $post_type = rand_str(20);
     813                register_post_type( $post_type );
     814                $this->factory->post->create_many( 10, array(
     815                        'post_type' => $post_type,
     816                        'post_author' => $this->author_id
     817                ) );
     818                $count1 = wp_count_posts( $post_type, 'readable' );
     819                $this->assertEquals( 10, $count1->publish );
     820                add_filter( 'count_posts', array( $this, 'filter_wp_count_posts' ) );
     821
     822                $count2 = wp_count_posts( $post_type, 'readable' );
     823                $this->assertEquals( 7, $count2->publish );
     824
     825                remove_filter( 'count_posts', array( $this, 'filter_wp_count_posts' ) );
     826        }
     827
     828        function filter_wp_count_posts( $counts ) {
     829                $counts->publish = 7;
     830                return $counts;
     831        }
     832
    811833        /**
    812834         * @ticket 22074
Note: See TracChangeset for help on using the changeset viewer.