/** * @covers ::bbp_decrease_user_topic_count */ public function test_bbp_decrease_user_topic_count() { $u = $this->factory->user->create(); $int_value = 3; $integer = true; bbp_update_user_topic_count($u, $int_value); $count = bbp_get_user_topic_count($u, $integer); $this->assertSame($int_value, $count); $t = $this->factory->topic->create(array('post_author' => $u)); // Minus 1 bbp_decrease_user_topic_count($t); $count = bbp_get_user_topic_count($u, $integer); $this->assertSame($int_value - 1, $count); // Minus 2 bbp_decrease_user_topic_count($t); $count = bbp_get_user_topic_count($u, $integer); $this->assertSame($int_value - 2, $count); }
/** * Bump the topic count for a user by a certain amount. * * @since 2.6.0 bbPress (r5309) * * @param int $user_id * @param int $difference * @uses bbp_get_user_topic_count() To get the users current topic count * @uses bbp_set_user_topic_count() To set the users new topic count */ function bbp_bump_user_topic_count($user_id = 0, $difference = 1) { // Bail if no bump if (empty($difference)) { return false; } // Validate user ID $user_id = bbp_get_user_id($user_id); if (empty($user_id)) { return false; } // Check meta for count, or query directly if not found $count = bbp_get_user_topic_count($user_id, true); if (empty($count)) { $count = bbp_get_user_topic_count_raw($user_id); } $difference = (int) $difference; $user_topic_count = (int) ($count + $difference); // Add them up and filter them $new_count = (int) apply_filters('bbp_bump_user_topic_count', $user_topic_count, $user_id, $difference, $count); return bbp_update_user_topic_count($user_id, $new_count); }