Ejemplo n.º 1
0
 /**
  * @group  counts
  * @covers ::bbp_get_public_child_count
  */
 public function test_bbp_get_public_child_count()
 {
     $f = $this->factory->forum->create();
     // Test initial forum public child counts
     $count = bbp_get_public_child_count($f, bbp_get_forum_post_type());
     $this->assertSame(0, $count);
     $count = bbp_get_public_child_count($f, bbp_get_topic_post_type());
     $this->assertSame(0, $count);
     /* Sub-Forums *********************************************************/
     $this->factory->forum->create_many(3, array('post_parent' => $f));
     $this->factory->forum->create(array('post_parent' => $f, 'post_status' => bbp_get_private_status_id()));
     $count = bbp_get_public_child_count($f, bbp_get_forum_post_type());
     $this->assertSame(3, $count);
     $this->factory->forum->create_many(2, array('post_parent' => $f));
     $count = bbp_get_public_child_count($f, bbp_get_forum_post_type());
     $this->assertSame(5, $count);
     /* Topics *************************************************************/
     $t1 = $this->factory->topic->create_many(3, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $this->factory->topic->create(array('post_parent' => $f, 'post_status' => bbp_get_spam_status_id(), 'topic_meta' => array('forum_id' => $f)));
     $count = bbp_get_public_child_count($f, bbp_get_topic_post_type());
     $this->assertSame(3, $count);
     $this->factory->topic->create_many(2, array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $count = bbp_get_public_child_count($f, bbp_get_topic_post_type());
     $this->assertSame(5, $count);
     /* Replies ************************************************************/
     $this->factory->reply->create_many(3, array('post_parent' => $t1[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $this->factory->reply->create(array('post_parent' => $t1[0], 'post_status' => bbp_get_spam_status_id(), 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = bbp_get_public_child_count($t1[0], bbp_get_reply_post_type());
     $this->assertSame(3, $count);
     $this->factory->reply->create_many(2, array('post_parent' => $t1[0], 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t1[0])));
     $count = bbp_get_public_child_count($t1[0], bbp_get_reply_post_type());
     $this->assertSame(5, $count);
 }
Ejemplo n.º 2
0
/**
 * Adjust the total reply count of a topic
 *
 * @since bbPress (r2467)
 *
 * @param int $topic_id Optional. Topic id to update
 * @param int $reply_count Optional. Set the reply count manually.
 * @uses bbp_is_reply() To check if the passed topic id is a reply
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_public_child_count() To get the reply count
 * @uses update_post_meta() To update the topic reply count meta
 * @uses apply_filters() Calls 'bbp_update_topic_reply_count' with the reply
 *                        count and topic id
 * @return int Topic reply count
 */
function bbp_update_topic_reply_count($topic_id = 0, $reply_count = 0)
{
    // If it's a reply, then get the parent (topic id)
    if (bbp_is_reply($topic_id)) {
        $topic_id = bbp_get_reply_topic_id($topic_id);
    } else {
        $topic_id = bbp_get_topic_id($topic_id);
    }
    // Get replies of topic if not passed
    if (empty($reply_count)) {
        $reply_count = bbp_get_public_child_count($topic_id, bbp_get_reply_post_type());
    }
    update_post_meta($topic_id, '_bbp_reply_count', (int) $reply_count);
    return apply_filters('bbp_update_topic_reply_count', (int) $reply_count, $topic_id);
}