Ticket #2978: 2978.diff
| File 2978.diff, 2.0 KB (added by , 10 years ago) |
|---|
-
src/includes/users/functions.php
1810 1810 $bbp_db = bbp_db(); 1811 1811 $where = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id ); 1812 1812 $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 ); 1813 1815 1814 1816 return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id ); 1815 1817 } … … 1842 1844 } 1843 1845 1844 1846 /** 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 */ 1855 function 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 /** 1845 1873 * Bump the topic count for a user by a certain amount. 1846 1874 * 1847 1875 * @since 2.6.0 bbPress (r5309) -
tests/phpunit/testcases/users/functions/counts.php
182 182 183 183 $count = bbp_get_user_topic_count_raw( $u ); 184 184 $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 ); 185 194 } 186 195 187 196 /**