bbp_update_forum_last_active_id( int $forum_id, int $active_id )
Update the forum last active post id
Description
Parameters
- $forum_id
-
(Optional) Forum id
- $active_id
-
(Optional) Active post id
Return
(bool) True on success, false on failure
Source
File: bp-forums/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 add together forum reply counts
$children = bbp_forum_query_subforum_ids( $forum_id );
if ( !empty( $children ) ) {
foreach ( (array) $children as $child ) {
$children_last_active = bbp_update_forum_last_active_id( $child, $active_id );
}
}
// Don't count replies if the forum is a category
$topic_ids = bbp_forum_query_topic_ids( $forum_id );
if ( !empty( $topic_ids ) ) {
$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 only if published
if ( bbp_get_public_status_id() === get_post_status( $active_id ) )
update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id );
return (int) apply_filters( 'bbp_update_forum_last_active_id', (int) $active_id, $forum_id );
}
Changelog
| Version | Description |
|---|---|
| bbPress (r2860) | 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.