Make WordPress Core

Ticket #32243: user.diff

File user.diff, 1.4 KB (added by nikonratm, 10 years ago)

Updated count_user_posts to accept multiple post types

  • user.php

     
    254254 *
    255255 * @global wpdb $wpdb WordPress database object for queries.
    256256 *
    257  * @param int    $userid    User ID.
    258  * @param string $post_type Optional. Post type to count the number of posts for. Default 'post'.
     257 * @param int           $userid User ID.
     258 * @param array/string  $post_types Optional. Post type(s) to count the number of posts for. Default 'post'.
    259259 * @return int Number of posts the user has written in this post type.
    260260 */
    261 function count_user_posts( $userid, $post_type = 'post' ) {
     261function count_user_posts( $userid, $post_types = 'post' ) {
    262262        global $wpdb;
     263       
     264        if ( is_string( $post_types ) ) $post_types = explode(',', $post_types);
    263265
    264         $where = get_posts_by_author_sql( $post_type, true, $userid );
     266        $where = get_posts_by_author_sql( $post_types, true, $userid );
    265267
    266268        $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
    267269
     
    273275         *
    274276         * @param int    $count     The user's post count.
    275277         * @param int    $userid    User ID.
    276          * @param string $post_type Post type to count the number of posts for.
     278         * @param array  $post_types Post types to count the number of posts for.
    277279         */
    278         return apply_filters( 'get_usernumposts', $count, $userid, $post_type );
     280        return apply_filters( 'get_usernumposts', $count, $userid, $post_types );
    279281}
    280282
    281283/**