bbp_update_forum_last_active_id

Update the forum last active post id.

Description

bbp_update_forum_last_active_id( (int) $forum_id = 0, (int) $active_id = 0 ); 

Parameters (2)

0. $forum_id — Optional. (int)
Forum id
1. $active_id — Optional. (int)
Active post id

Usage

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

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_update_forum_last_active_id( $forum_id = 0, $active_id = 0 ) { 
  2.  
  3. $forum_id = bbp_get_forum_id( $forum_id ); 
  4.  
  5. // Define local variable(s) 
  6. $children_last_active = 0; 
  7.  
  8. // Do some calculation if not manually set 
  9. if ( empty( $active_id ) ) { 
  10.  
  11. // Loop through children and add together forum reply counts 
  12. $children = bbp_forum_query_subforum_ids( $forum_id ); 
  13. if ( !empty( $children ) ) { 
  14. foreach ( (array) $children as $child ) { 
  15. $children_last_active = bbp_update_forum_last_active_id( $child, $active_id ); 
  16.  
  17. // Don't count replies if the forum is a category 
  18. $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 
  19. if ( !empty( $topic_ids ) ) { 
  20. $active_id = bbp_forum_query_last_reply_id( $forum_id, $topic_ids ); 
  21. $active_id = $active_id > max( $topic_ids ) ? $active_id : max( $topic_ids ); 
  22.  
  23. // Forum has no topics 
  24. } else { 
  25. $active_id = 0; 
  26.  
  27. // Cast as integer in case of empty or string 
  28. $active_id = (int) $active_id; 
  29. $children_last_active = (int) $children_last_active; 
  30.  
  31. // If child forums have higher id, use that instead 
  32. if ( !empty( $children ) && ( $children_last_active > $active_id ) ) 
  33. $active_id = $children_last_active; 
  34.  
  35. // Update only if published 
  36. if ( bbp_get_public_status_id() === get_post_status( $active_id ) ) 
  37. update_post_meta( $forum_id, '_bbp_last_active_id', (int) $active_id ); 
  38.  
  39. return (int) apply_filters( 'bbp_update_forum_last_active_id', (int) $active_id, $forum_id );