Skip to:
Content

bbPress.org

Ticket #2978: 2978.diff

File 2978.diff, 2.0 KB (added by netweb, 5 years ago)
  • src/includes/users/functions.php

     
    18101810        $bbp_db = bbp_db();
    18111811        $where  = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id );
    18121812        $count  = (int) $bbp_db->get_var( "SELECT COUNT(*) FROM {$bbp_db->posts} {$where}" );
     1813        // Manually add the user closed topic count, see #bbPress2978 and #WP12706
     1814        $count  = $count + bbp_get_user_closed_topic_count( $user_id );
    18131815
    18141816        return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id );
    18151817}
     
    18421844}
    18431845
    18441846/**
     1847 * Return the raw database count of closed topics by a user
     1848 *
     1849 * @since 2.6.0 bbPress (rXXXX)
     1850 *
     1851 * @param int $user_id User ID to get count for
     1852 *
     1853 * @return int Raw DB count of user closed topics
     1854 */
     1855function bbp_get_user_closed_topic_count( $user_id = 0 ) {
     1856        $user_id = bbp_get_user_id( $user_id );
     1857        if ( empty( $user_id ) ) {
     1858                return false;
     1859        }
     1860
     1861        $bbp_db = bbp_db();
     1862        $count  = (int) $bbp_db->get_var( "SELECT COUNT(*)
     1863                FROM {$bbp_db->posts}
     1864                WHERE post_type = '" . bbp_get_topic_post_type() . "'
     1865                AND post_status = '" . bbp_get_closed_status_id() . "'
     1866                AND post_author = $user_id;"
     1867        );
     1868
     1869        return (int) apply_filters( 'bbp_get_user_closed_topic_count', $count, $user_id );
     1870}
     1871
     1872/**
    18451873 * Bump the topic count for a user by a certain amount.
    18461874 *
    18471875 * @since 2.6.0 bbPress (r5309)
  • tests/phpunit/testcases/users/functions/counts.php

     
    182182
    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
    187196        /**