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 meta data of forums above it. This calls several 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 Description


Parameters 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


Top ↑

Source Source

File: includes/topics/functions.php

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 ) ) {

				// Get the forum
				$forum = bbp_get_forum( $ancestor );

				// Update the forum
				bbp_update_forum( array(
					'forum_id'           => $forum->ID,
					'post_parent'        => $forum->post_parent,
					'last_topic_id'      => $topic_id,
					'last_reply_id'      => $reply_id,
					'last_active_id'     => $active_id,
					'last_active_time'   => $last_active_time,
					'last_active_status' => $topic_status
				) );
			}
		}
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.