Make WordPress Core

Changeset 25578


Ignore:
Timestamp:
09/23/2013 07:07:08 PM (13 years ago)
Author:
nacin
Message:

In wp_count_posts(), rename 'count_posts' hook to 'wp_count_posts', for clarity. see #16603.

Location:
trunk
Files:
2 edited

Legend:

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

    r25572 r25578  
    21102110
    21112111        $counts = wp_cache_get( $cache_key, 'counts' );
    2112         if ( false !== $counts ) {
    2113                 /**
    2114                  * Modify returned post counts by status for the current post type.
    2115                  *
    2116                  * @since 3.7.0
    2117                  *
    2118                  * @param object $counts An object containing the current post_type's post counts by status.
    2119                  * @param string $type   The post type.
    2120                  * @param string $perm   The permission to determine if the posts are 'readable' by the current user.
    2121                  */
    2122                 return apply_filters( 'count_posts', $counts, $type, $perm );
    2123         }
    2124 
    2125         $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    2126 
    2127         $counts = array_fill_keys( get_post_stati(), 0 );
    2128 
    2129         foreach ( $results as $row )
    2130                 $counts[ $row['post_status'] ] = $row['num_posts'];
    2131 
    2132         $counts = (object) $counts;
    2133         wp_cache_set( $cache_key, $counts, 'counts' );
    2134 
    2135         //duplicate_hook
    2136         return apply_filters( 'count_posts', $counts, $type, $perm );
     2112        if ( false === $counts ) {
     2113                $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
     2114                $counts = array_fill_keys( get_post_stati(), 0 );
     2115
     2116                foreach ( $results as $row )
     2117                        $counts[ $row['post_status'] ] = $row['num_posts'];
     2118
     2119                $counts = (object) $counts;
     2120                wp_cache_set( $cache_key, $counts, 'counts' );
     2121        }
     2122
     2123        /**
     2124         * Modify returned post counts by status for the current post type.
     2125         *
     2126         * @since 3.7.0
     2127         *
     2128         * @param object $counts An object containing the current post_type's post counts by status.
     2129         * @param string $type   The post type.
     2130         * @param string $perm   The permission to determine if the posts are 'readable' by the current user.
     2131         */
     2132        return apply_filters( 'wp_count_posts', $counts, $type, $perm );
    21372133}
    21382134
  • trunk/tests/phpunit/tests/post.php

    r25554 r25578  
    818818                $count1 = wp_count_posts( $post_type, 'readable' );
    819819                $this->assertEquals( 10, $count1->publish );
    820                 add_filter( 'count_posts', array( $this, 'filter_wp_count_posts' ) );
     820                add_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
    821821
    822822                $count2 = wp_count_posts( $post_type, 'readable' );
    823823                $this->assertEquals( 7, $count2->publish );
    824824
    825                 remove_filter( 'count_posts', array( $this, 'filter_wp_count_posts' ) );
     825                remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
    826826        }
    827827
Note: See TracChangeset for help on using the changeset viewer.