Skip to:
Content

bbPress.org

Changeset 6609


Ignore:
Timestamp:
07/03/2017 11:22:01 PM (4 years ago)
Author:
johnjamesjacoby
Message:

Counts: Remove count_user_posts() usages, and always return an int.

User topic & reply counts haven't included closed status for topics, and these wrappers should include support for things like view=all later.

Fixes #3124.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/users/functions.php

    r6601 r6609  
    621621function bbp_get_user_topic_count_raw( $user_id = 0 ) {
    622622    $user_id = bbp_get_user_id( $user_id );
    623     if ( empty( $user_id ) ) {
    624         return false;
    625     }
    626 
    627     $count = count_user_posts( $user_id, bbp_get_topic_post_type(), false );
    628     // Manually add the user closed topic count, see #2978 and #WP12706
    629     $count = $count + bbp_get_user_closed_topic_count( $user_id );
     623    $bbp_db  = bbp_db();
     624    $statii  = "'" . implode( "', '", bbp_get_public_topic_statuses() ) . "'";
     625    $sql     = "SELECT COUNT(*)
     626            FROM {$bbp_db->posts}
     627            WHERE post_author = %d
     628                AND post_type = %s
     629                AND post_status IN ({$statii})";
     630
     631    $query   = $bbp_db->prepare( $sql, $user_id, bbp_get_topic_post_type() );
     632    $count   = (int) $bbp_db->get_var( $query );
    630633
    631634    // Filter & return
     
    644647function bbp_get_user_reply_count_raw( $user_id = 0 ) {
    645648    $user_id = bbp_get_user_id( $user_id );
    646     if ( empty( $user_id ) ) {
    647         return false;
    648     }
    649 
    650     $count = count_user_posts( $user_id, bbp_get_reply_post_type(), false );
     649    $bbp_db  = bbp_db();
     650    $sql     = "SELECT COUNT(*)
     651            FROM {$bbp_db->posts}
     652            WHERE post_author = %d
     653                AND post_type = %s
     654                AND post_status %s";
     655
     656    $query   = $bbp_db->prepare( $sql, $user_id, bbp_get_reply_post_type(), bbp_get_public_status_id() );
     657    $count   = (int) $bbp_db->get_var( $query );
    651658
    652659    // Filter & return
     
    665672function bbp_get_user_closed_topic_count( $user_id = 0 ) {
    666673    $user_id = bbp_get_user_id( $user_id );
    667     if ( empty( $user_id ) ) {
    668         return false;
    669     }
    670 
    671     $bbp_db = bbp_db();
    672     $count  = (int) $bbp_db->get_var( $bbp_db->prepare(
     674    $bbp_db  = bbp_db();
     675    $count   = (int) $bbp_db->get_var( $bbp_db->prepare(
    673676        "SELECT COUNT(*)
    674677            FROM {$bbp_db->posts}
Note: See TracChangeset for help on using the changeset viewer.