Example #1
0
 /**
  * @covers ::bbp_get_public_child_last_id
  */
 public function test_bbp_get_public_child_last_id()
 {
     $f = $this->factory->forum->create();
     $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f)));
     $last_id = bbp_get_public_child_last_id($f, bbp_get_topic_post_type());
     $this->assertSame($t, $last_id);
     $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t)));
     $last_id = bbp_get_public_child_last_id($t, bbp_get_reply_post_type());
     $this->assertSame($r, $last_id);
 }
Example #2
0
/**
 * Update the topic with the most recent reply ID
 *
 * @since bbPress (r2625)
 *
 * @param int $topic_id Optional. Topic id to update
 * @param int $reply_id Optional. Reply id
 * @uses bbp_is_reply() To check if the passed topic id is a reply
 * @uses bbp_get_reply_id() To get the reply id
 * @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_last_id() To get the last public reply id
 * @uses update_post_meta() To update the topic last reply id meta
 * @uses apply_filters() Calls 'bbp_update_topic_last_reply_id' with the reply
 *                        id and topic id
 * @return int Reply id
 */
function bbp_update_topic_last_reply_id($topic_id = 0, $reply_id = 0)
{
    // If it's a reply, then get the parent (topic id)
    if (empty($reply_id) && bbp_is_reply($topic_id)) {
        $reply_id = bbp_get_reply_id($topic_id);
        $topic_id = bbp_get_reply_topic_id($reply_id);
    } else {
        $reply_id = bbp_get_reply_id($reply_id);
        $topic_id = bbp_get_topic_id($topic_id);
    }
    if (empty($reply_id)) {
        $reply_id = bbp_get_public_child_last_id($topic_id, bbp_get_reply_post_type());
    }
    // Adjust last_id's based on last_reply post_type
    if (empty($reply_id) || !bbp_is_reply($reply_id)) {
        $reply_id = 0;
    }
    // Update if reply is published
    if (bbp_is_reply_published($reply_id)) {
        update_post_meta($topic_id, '_bbp_last_reply_id', (int) $reply_id);
    }
    return apply_filters('bbp_update_topic_last_reply_id', (int) $reply_id, $topic_id);
}