Skip to:
Content

bbPress.org

Changeset 3633


Ignore:
Timestamp:
11/26/2011 09:24:26 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Introduce raw functions for getting user topic and reply post counts directly from the posts table. See #1694.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-user-functions.php

    r3607 r3633  
    161161
    162162    return apply_filters( 'bbp_current_author_ua', $retval );
     163}
     164
     165/** Post Counts ***************************************************************/
     166
     167/**
     168 * Return the raw database count of topics by a user
     169 *
     170 * @since bbPress (r3633)
     171 * @global WPDB $wpdb
     172 * @uses bbp_get_user_id()
     173 * @uses get_posts_by_author_sql()
     174 * @uses bbp_get_topic_post_type()
     175 * @uses apply_filters()
     176 * @return int Raw DB count of topics
     177 */
     178function bbp_get_user_topic_count_raw( $user_id = 0 ) {
     179    if ( !$user_id = bbp_get_user_id( $user_id ) )
     180        return false;
     181
     182    global $wpdb;
     183
     184    $where = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id );
     185    $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" );
     186
     187    return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id );
     188}
     189
     190/**
     191 * Return the raw database count of replies by a user
     192 *
     193 * @since bbPress (r3633)
     194 * @global WPDB $wpdb
     195 * @uses bbp_get_user_id()
     196 * @uses get_posts_by_author_sql()
     197 * @uses bbp_get_reply_post_type()
     198 * @uses apply_filters()
     199 * @return int Raw DB count of replies
     200 */
     201function bbp_get_user_reply_count_raw( $user_id = 0 ) {
     202    if ( !$user_id = bbp_get_user_id( $user_id ) )
     203        return false;
     204
     205    global $wpdb;
     206
     207    $where = get_posts_by_author_sql( bbp_get_reply_post_type(), true, $user_id );
     208    $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" );
     209
     210    return (int) apply_filters( 'bbp_get_user_reply_count_raw', $count, $user_id );
    163211}
    164212
Note: See TracChangeset for help on using the changeset viewer.