Skip to:
Content

bbPress.org

Changeset 6114


Ignore:
Timestamp:
11/02/2016 10:24:30 AM (3 years ago)
Author:
netweb
Message:

Users: Include users closed topic counts in bbp_get_user_topic_count_raw()

This changeset works around an issue where the lack of custom post statuses support upstream in #WP12706 prevents us from including users closed topics counts in a users raw topic count. See also #meta1870

Props netweb.
Fixes #2978.

Location:
trunk
Files:
2 edited

Legend:

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

    r6111 r6114  
    18171817    $where  = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id );
    18181818    $count  = (int) $bbp_db->get_var( "SELECT COUNT(*) FROM {$bbp_db->posts} {$where}" );
     1819    // Manually add the user closed topic count, see #2978 and #WP12706
     1820    $count  = $count + bbp_get_user_closed_topic_count( $user_id );
    18191821
    18201822    return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id );
     
    18461848
    18471849    return (int) apply_filters( 'bbp_get_user_reply_count_raw', $count, $user_id );
     1850}
     1851
     1852/**
     1853 * Return the raw database count of closed topics by a user
     1854 *
     1855 * @since 2.6.0 bbPress (r6113)
     1856 *
     1857 * @param int $user_id User ID to get count for
     1858 *
     1859 * @return int Raw DB count of user closed topics
     1860 */
     1861function bbp_get_user_closed_topic_count( $user_id = 0 ) {
     1862    $user_id = bbp_get_user_id( $user_id );
     1863    if ( empty( $user_id ) ) {
     1864        return false;
     1865    }
     1866
     1867    $bbp_db = bbp_db();
     1868    $count  = (int) $bbp_db->get_var( "SELECT COUNT(*)
     1869        FROM {$bbp_db->posts}
     1870        WHERE post_type = '" . bbp_get_topic_post_type() . "'
     1871        AND post_status = '" . bbp_get_closed_status_id() . "'
     1872        AND post_author = $user_id;"
     1873    );
     1874
     1875    return (int) apply_filters( 'bbp_get_user_closed_topic_count', $count, $user_id );
    18481876}
    18491877
  • trunk/tests/phpunit/testcases/users/functions/counts.php

    r5919 r6114  
    183183        $count = bbp_get_user_topic_count_raw( $u );
    184184        $this->assertSame( 6, $count );
     185
     186        $t = $this->factory->topic->create( array(
     187            'post_author' => $u,
     188        ) );
     189
     190        bbp_close_topic( $t );
     191
     192        $count = bbp_get_user_topic_count_raw( $u );
     193        $this->assertSame( 7, $count );
    185194    }
    186195
Note: See TracChangeset for help on using the changeset viewer.