bbp_update_forum_last_reply_id

Update the forum last reply id.

Description

bbp_update_forum_last_reply_id( (int) $forum_id = 0, (int) $reply_id = 0 ); 

Parameters (2)

0. $forum_id — Optional. (int)
Forum id
1. $reply_id — Optional. (int)
Reply id

Usage

  1. if ( !function_exists( 'bbp_update_forum_last_reply_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // Optional. Forum id 
  5. $forum_id = -1; 
  6.  
  7. // Optional. Reply id 
  8. $reply_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_update_forum_last_reply_id($forum_id, $reply_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/forums/functions.php  
  1. function bbp_update_forum_last_reply_id( $forum_id = 0, $reply_id = 0 ) { 
  2. $forum_id = bbp_get_forum_id( $forum_id ); 
  3.  
  4. // Define local variable(s) 
  5. $children_last_reply = 0; 
  6.  
  7. // Do some calculation if not manually set 
  8. if ( empty( $reply_id ) ) { 
  9.  
  10. // Loop through children and get the most recent reply id 
  11. $children = bbp_forum_query_subforum_ids( $forum_id ); 
  12. if ( !empty( $children ) ) { 
  13. foreach ( (array) $children as $child ) { 
  14. $children_last_reply = bbp_update_forum_last_reply_id( $child ); // Recursive 
  15.  
  16. // If this forum has topics... 
  17. $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 
  18. if ( !empty( $topic_ids ) ) { 
  19.  
  20. // ...get the most recent reply from those topics... 
  21. $reply_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids ); 
  22.  
  23. // ...and compare it to the most recent topic id... 
  24. $reply_id = ( $reply_id > max( $topic_ids ) ) ? $reply_id : max( $topic_ids ); 
  25.  
  26. // Cast as integer in case of empty or string 
  27. $reply_id = (int) $reply_id; 
  28. $children_last_reply = (int) $children_last_reply; 
  29.  
  30. // If child forums have higher ID, check for newer reply id 
  31. if ( !empty( $children ) && ( $children_last_reply > $reply_id ) ) 
  32. $reply_id = $children_last_reply; 
  33.  
  34. // Update the last public reply ID 
  35. if ( bbp_is_reply_published( $reply_id ) ) 
  36. update_post_meta( $forum_id, '_bbp_last_reply_id', $reply_id ); 
  37.  
  38. return (int) apply_filters( 'bbp_update_forum_last_reply_id', $reply_id, $forum_id );