Make WordPress Core


Ignore:
Timestamp:
05/21/2015 06:42:49 PM (10 years ago)
Author:
boonebgorges
Message:

Support multiple post types in count_user_posts() and other functions that use get_posts_by_author_sql().

Props nikonratm.
Fixes #32243.

File:
1 edited

Legend:

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

    r32207 r32523  
    252252 * @since 3.0.0
    253253 * @since 4.1.0 Added `$post_type` argument.
     254 * @since 4.3.0 Added `$public_only` argument.
    254255 *
    255256 * @global wpdb $wpdb WordPress database object for queries.
    256257 *
    257  * @param int    $userid    User ID.
    258  * @param string $post_type Optional. Post type to count the number of posts for. Default 'post'.
     258 * @param int          $userid      User ID.
     259 * @param array|string $post_type   Optional. Post type(s) to count the number of posts for. Default 'post'.
     260 * @param bool         $public_only Optional. Only return counts for public posts. Defaults to false.
    259261 * @return int Number of posts the user has written in this post type.
    260262 */
    261 function count_user_posts( $userid, $post_type = 'post' ) {
     263function count_user_posts( $userid, $post_type = 'post', $public_only = false ) {
    262264    global $wpdb;
    263265
    264     $where = get_posts_by_author_sql( $post_type, true, $userid );
     266    $where = get_posts_by_author_sql( $post_type, true, $userid, $public_only );
    265267
    266268    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
     
    271273     * @since 2.7.0
    272274     * @since 4.1.0 Added `$post_type` argument.
    273      *
    274      * @param int    $count     The user's post count.
    275      * @param int    $userid    User ID.
    276      * @param string $post_type Post type to count the number of posts for.
     275     * @since 4.3.0 Added `$public_only` argument.
     276     *
     277     * @param int          $count       The user's post count.
     278     * @param int          $userid      User ID.
     279     * @param string|array $post_types  Post types to count the number of posts for.
     280     * @param bool         $public_only Whether to limit counted posts to public posts.
    277281     */
    278282    return apply_filters( 'get_usernumposts', $count, $userid, $post_type );
     
    284288 * @since 3.0.0
    285289 *
    286  * @param array $users Array of user IDs.
    287  * @param string $post_type Optional. Post type to check. Defaults to post.
    288  * @param bool $public_only Optional. Only return counts for public posts.  Defaults to false.
     290 * @param array        $users      Array of user IDs.
     291 * @param string|array $post_type   Optional. Array or comma-separated list of post types to check. Defaults to 'post'.
     292 * @param bool         $public_only Optional. Only return counts for public posts.  Defaults to false.
    289293 * @return array Amount of posts each user has written.
    290294 */
Note: See TracChangeset for help on using the changeset viewer.