bbp_update_topic_walker( int $topic_id, string $last_active_time = '', int $forum_id, int $reply_id, bool $refresh = true )

Walks up the post_parent tree from the current topic_id, and updates the counts of forums above it. This calls a few internal functions that all run manual queries against the database to get their results. As such, this function can be costly to run but is necessary to keep everything accurate.

Description

Parameters

$topic_id

(Required) Topic id

$last_active_time

(Optional) Last active time

Default value: ''

$forum_id

(Optional) Forum id

$reply_id

(Optional) Reply id

$refresh

(Optional) Reset all the previous parameters? Defaults to true.

Default value: true

Source

File: bp-forums/topics/functions.php

980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
function bbp_update_topic_walker( $topic_id, $last_active_time = '', $forum_id = 0, $reply_id = 0, $refresh = true ) {
 
    // Validate topic_id
    $topic_id  = bbp_get_topic_id( $topic_id );
 
    // Define local variable(s)
    $active_id = 0;
 
    // Topic was passed
    if ( !empty( $topic_id ) ) {
 
        // Get the forum ID if none was passed
        if ( empty( $forum_id )  ) {
            $forum_id = bbp_get_topic_forum_id( $topic_id );
        }
 
        // Set the active_id based on topic_id/reply_id
        $active_id = empty( $reply_id ) ? $topic_id : $reply_id;
    }
 
    // Get topic ancestors
    $ancestors = array_values( array_unique( array_merge( array( $forum_id ), (array) get_post_ancestors( $topic_id ) ) ) );
 
    // Topic status
    $topic_status = get_post_status( $topic_id );
 
    // If we want a full refresh, unset any of the possibly passed variables
    if ( true === $refresh ) {
        $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0;
        $topic_status = bbp_get_public_status_id();
    }
 
    // Loop through ancestors
    if ( !empty( $ancestors ) ) {
        foreach ( $ancestors as $ancestor ) {
 
            // If ancestor is a forum, update counts
            if ( bbp_is_forum( $ancestor ) ) {
 
                // Update the forum
                bbp_update_forum( array(
                    'forum_id'           => $ancestor,
                    'last_topic_id'      => $topic_id,
                    'last_reply_id'      => $reply_id,
                    'last_active_id'     => $active_id,
                    'last_active_time'   => 0,
                    'last_active_status' => $topic_status
                ) );
            }
        }
    }
}

Changelog

Changelog
Version Description
bbPress (r2800) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.