Make WordPress Core

Changeset 30322


Ignore:
Timestamp:
11/13/2014 02:18:30 AM (9 years ago)
Author:
boonebgorges
Message:

Introduce $post_type param for count_user_posts().

Props Caspie, engelen, DrewAPicture.
Fixes #21364.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r30122 r30322  
    251251 *
    252252 * @since 3.0.0
     253 * @since 4.0.0 Added $post_type parameter.
    253254 *
    254255 * @global wpdb $wpdb WordPress database object for queries.
    255256 *
    256  * @param int $userid User ID.
    257  * @return int Amount of posts user has written.
    258  */
    259 function count_user_posts($userid) {
     257 * @param int    $userid    User ID.
     258 * @param string $post_type Optional. Post type to count the number of posts for. Default 'post'.
     259 * @return int Number of posts the user has written in this post type.
     260 */
     261function count_user_posts( $userid, $post_type = 'post' ) {
    260262    global $wpdb;
    261263
    262     $where = get_posts_by_author_sql('post', true, $userid);
     264    $where = get_posts_by_author_sql( $post_type, true, $userid );
    263265
    264266    $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
     
    268270     *
    269271     * @since 2.7.0
    270      *
    271      * @param int $count  The user's post count.
    272      * @param int $userid User ID.
    273      */
    274     return apply_filters( 'get_usernumposts', $count, $userid );
     272     * @since 4.0.0 Added $post_type parameter.
     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.
     277     */
     278    return apply_filters( 'get_usernumposts', $count, $userid, $post_type );
    275279}
    276280
Note: See TracChangeset for help on using the changeset viewer.