/** * Return a users total post count * * @since 2.1.0 bbPress (r3632) * * @param int $user_id * @param boolean $integer Optional. Whether or not to format the result * @uses bbp_get_user_id() * @uses get_user_option() * @uses apply_filters() * @return string */ function bbp_get_user_post_count($user_id = 0, $integer = false) { // Validate user id $user_id = bbp_get_user_id($user_id); if (empty($user_id)) { return false; } $topics = bbp_get_user_topic_count($user_id, true); $replies = bbp_get_user_reply_count($user_id, true); $count = (int) $topics + $replies; $filter = true === $integer ? 'bbp_get_user_post_count_int' : 'bbp_get_user_post_count'; return apply_filters($filter, $count, $user_id); }
/** * @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); }
/** * Return a users total post count * * @since bbPress (r3632) * * @param int $user_id * @uses bbp_get_user_id() * @uses get_user_option() * @uses apply_filters() * @return string */ function bbp_get_user_post_count($user_id = 0) { // Validate user id $user_id = bbp_get_user_id($user_id); if (empty($user_id)) { return false; } $topics = bbp_get_user_topic_count($user_id); $replies = bbp_get_user_reply_count($user_id); $count = (int) $topics + (int) $replies; return apply_filters('bbp_get_user_post_count', (int) $count, $user_id); }
echo site_url("/author/") . $nicename . "/"; ?> " title="<?php printf(esc_attr__("%s's blog posts", 'govintranet'), bbp_get_displayed_user_field('display_name')); ?> "><?php _e('Blog posts', 'govintranet'); ?> </a> </span> </li> <?php } // Show forum links? if (get_option('options_forum_support')) { if (bbp_get_user_topic_count()) { ?> <li class="<?php if (bbp_is_single_user_topics()) { ?> current<?php } ?> "> <span class='bbp-user-topics-created-link'> <a href="<?php bbp_user_topics_created_url(); ?> " title="<?php printf(esc_attr__("%s's forum topics", 'govintranet'), bbp_get_displayed_user_field('display_name')); ?>