Ejemplo n.º 1
0
/**
 * Increase the total topic count of a forum by one.
 *
 * @since 2.6.0 bbPress (r6036)
 *
 * @param int $forum_id The forum id.
 *
 * @uses bbp_is_topic() To get the topic id
 * @uses bbp_get_topic_forum_id() To get the topics forum id
 * @uses bbp_is_topic_published() To get the topics published status
 * @uses bbp_is_topic_closed() To get the topics closed status
 * @uses bbp_increase_forum_topic_count_hidden() To increase the forums hidden
 *                                                topic count by 1
 * @uses bbp_bump_forum_topic_count() To bump the forum topic count
 *
 * @return void
 */
function bbp_increase_forum_topic_count($forum_id = 0)
{
    // Bail early if no id is passed.
    if (empty($forum_id)) {
        return;
    }
    // If it's a topic, get the forum id.
    if (bbp_is_topic($forum_id)) {
        $topic_id = $forum_id;
        $forum_id = bbp_get_topic_forum_id($topic_id);
        // If this is a new, unpublished, topic, increase hidden count and bail.
        if ('bbp_new_topic' === current_filter() && (!bbp_is_topic_published($topic_id) && !bbp_is_topic_closed($topic_id))) {
            bbp_increase_forum_topic_count_hidden($forum_id);
            return;
        }
    }
    bbp_bump_forum_topic_count($forum_id);
}
Ejemplo n.º 2
0
/**
 * Update counts after a topic is inserted via `bbp_insert_topic`.
 *
 * @since 2.6.0 bbPress (r6036)
 *
 * @param int $topic_id The topic id.
 * @param int $forum_id The forum id.
 *
 * @uses bbp_get_topic_status() To get the post status
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_increase_forum_topic_count() To bump the topic's forum topic count by 1
 * @uses bbp_increase_forum_topic_count_hidden() To bump the topic's forum topic
 *                                               hidden count by 1
 *
 * @return void
 */
function bbp_insert_topic_update_counts($topic_id = 0, $forum_id = 0)
{
    // If the topic is public, update the forum topic counts.
    if (bbp_get_topic_status($topic_id) === bbp_get_public_status_id()) {
        bbp_increase_forum_topic_count($forum_id);
        // If the topic isn't public only update the forum topic hidden count.
    } else {
        bbp_increase_forum_topic_count_hidden($forum_id);
    }
}
Ejemplo n.º 3
0
 /**
  * @covers ::bbp_increase_forum_topic_count_hidden
  */
 public function test_bbp_increase_forum_topic_count_hidden()
 {
     $f = $this->factory->forum->create();
     $count = bbp_get_forum_topic_count_hidden($f);
     $this->assertSame('0', $count);
     bbp_increase_forum_topic_count_hidden($f);
     $count = bbp_get_forum_topic_count_hidden($f);
     $this->assertSame('1', $count);
 }