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
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 | 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.