bbp_update_forum_last_reply_id( int $forum_id, int $reply_id )
Update the forum last reply id
Description
Parameters
- $forum_id
-
(Optional) Forum id
- $reply_id
-
(Optional) Reply id
Return
(bool) True on success, false on failure
Source
File: bp-forums/forums/functions.php
function bbp_update_forum_last_reply_id( $forum_id = 0, $reply_id = 0 ) { $forum_id = bbp_get_forum_id( $forum_id ); // Define local variable(s) $children_last_reply = 0; // Do some calculation if not manually set if ( empty( $reply_id ) ) { // Loop through children and get the most recent reply id $children = bbp_forum_query_subforum_ids( $forum_id ); if ( !empty( $children ) ) { foreach ( (array) $children as $child ) { $children_last_reply = bbp_update_forum_last_reply_id( $child ); // Recursive } } // If this forum has topics... $topic_ids = bbp_forum_query_topic_ids( $forum_id ); if ( !empty( $topic_ids ) ) { // ...get the most recent reply from those topics... $reply_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids ); // ...and compare it to the most recent topic id... $reply_id = ( $reply_id > max( $topic_ids ) ) ? $reply_id : max( $topic_ids ); } } // Cast as integer in case of empty or string $reply_id = (int) $reply_id; $children_last_reply = (int) $children_last_reply; // If child forums have higher ID, check for newer reply id if ( !empty( $children ) && ( $children_last_reply > $reply_id ) ) $reply_id = $children_last_reply; // Update the last public reply ID if ( bbp_is_reply_published( $reply_id ) ) update_post_meta( $forum_id, '_bbp_last_reply_id', $reply_id ); return (int) apply_filters( 'bbp_update_forum_last_reply_id', $reply_id, $forum_id ); }
Changelog
Version | Description |
---|---|
bbPress (r2625) | 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.