Make WordPress Core


Ignore:
Timestamp:
04/28/2011 11:27:39 AM (14 years ago)
Author:
nacin
Message:

Use the post type object in get_posts_by_author_sql() and add a post type parameter to count_many_users_posts(). The formerly somewhat useless and now totally useless pub_priv_sql_capability filter is considered deprecated. fixes #17220.

File:
1 edited

Legend:

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

    r17699 r17742  
    166166 *
    167167 * @since 3.0.0
    168  * @param array $users User ID number list.
     168 * @param array $user_ids Array of user IDs.
     169 * @param string|array $post_type Optional. Post type to check. Defaults to post.
    169170 * @return array Amount of posts each user has written.
    170171 */
    171 function count_many_users_posts($users) {
     172function count_many_users_posts($users, $post_type = 'post' ) {
    172173    global $wpdb;
    173174
    174175    $count = array();
    175     if ( ! is_array($users) || empty( $users ) )
     176    if ( empty( $users ) || ! is_array( $users ) )
    176177        return $count;
    177178
    178     $userlist = implode( ',', $users );
    179     $where = get_posts_by_author_sql( 'post' );
     179    $userlist = implode( ',', array_map( 'absint', $users ) );
     180    $where = get_posts_by_author_sql( $post_type );
    180181
    181182    $result = $wpdb->get_results( "SELECT post_author, COUNT(*) FROM $wpdb->posts $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_N );
Note: See TracChangeset for help on using the changeset viewer.