bbp_update_forum_last_active_id( int $forum_id, int $active_id )
Update the forum last active post id
Description Description
Parameters Parameters
- $forum_id
-
(Optional) Forum id.
- $active_id
-
(Optional) Active post id.
Return Return
(int) Id of the forums last active post
Source Source
File: includes/forums/functions.php
function bbp_update_forum_last_active_id( $forum_id = 0, $active_id = 0 ) { $forum_id = bbp_get_forum_id( $forum_id ); // Define local variable(s) $children_last_active = 0; // Do some calculation if not manually set if ( empty( $active_id ) ) { // Loop through children and get the last active ID $children = bbp_forum_query_subforum_ids( $forum_id ); if ( ! empty( $children ) ) { foreach ( $children as $child ) { $children_last_active = bbp_update_forum_last_active_id( $child, $active_id ); } } // Get topic IDs and only accept larger IDs $topic_ids = bbp_forum_query_topic_ids( $forum_id ); if ( ! empty( $topic_ids ) ) { // Make sure ID is larger $active_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids ); $active_id = $active_id > max( $topic_ids ) ? $active_id : max( $topic_ids ); // Forum has no topics } else { $active_id = 0; } } // Cast as integer in case of empty or string $active_id = (int) $active_id; $children_last_active = (int) $children_last_active; // If child forums have higher ID, use that instead if ( ! empty( $children ) && ( $children_last_active > $active_id ) ) { $active_id = $children_last_active; } update_post_meta( $forum_id, '_bbp_last_active_id', $active_id ); // Filter & return return (int) apply_filters( 'bbp_update_forum_last_active_id', $active_id, $forum_id ); }
Changelog Changelog
Version | Description |
---|---|
2.0.0 | Introduced. |