bbp_update_forum

Updates the counts of a forum.

Description

bbp_update_forum( (string) $args = '' ); 

This calls a few internal functions that all run manual queries against the database to get their results. As such, this function can be costly to run but is necessary to keep everything accurate.

Parameters (1)

0. $args — Optional. (string) => ''
Supports these arguments: - forum_id: Forum id - last_topic_id: Last topic id - last_reply_id: Last reply id - last_active_id: Last active post id - last_active_time: last active time

Usage

  1. if ( !function_exists( 'bbp_update_forum' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3. $args = ''; 
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bbp_update_forum($args); 
  7.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_update_forum( $args = '' ) { 
  2.  
  3. // Parse arguments against default values 
  4. $r = bbp_parse_args( $args, array( 
  5. 'forum_id' => 0,  
  6. 'post_parent' => 0,  
  7. 'last_topic_id' => 0,  
  8. 'last_reply_id' => 0,  
  9. 'last_active_id' => 0,  
  10. 'last_active_time' => 0,  
  11. 'last_active_status' => bbp_get_public_status_id() 
  12. ), 'update_forum' ); 
  13.  
  14. // Last topic and reply ID's 
  15. bbp_update_forum_last_topic_id( $r['forum_id'], $r['last_topic_id'] ); 
  16. bbp_update_forum_last_reply_id( $r['forum_id'], $r['last_reply_id'] ); 
  17.  
  18. // Active dance 
  19. $r['last_active_id'] = bbp_update_forum_last_active_id( $r['forum_id'], $r['last_active_id'] ); 
  20.  
  21. // If no active time was passed, get it from the last_active_id 
  22. if ( empty( $r['last_active_time'] ) ) { 
  23. $r['last_active_time'] = get_post_field( 'post_date', $r['last_active_id'] ); 
  24.  
  25. if ( bbp_get_public_status_id() === $r['last_active_status'] ) { 
  26. bbp_update_forum_last_active_time( $r['forum_id'], $r['last_active_time'] ); 
  27.  
  28. // Counts 
  29. bbp_update_forum_subforum_count ( $r['forum_id'] ); 
  30. bbp_update_forum_reply_count ( $r['forum_id'] ); 
  31. bbp_update_forum_topic_count ( $r['forum_id'] ); 
  32.  
  33. // Update the parent forum if one was passed 
  34. if ( !empty( $r['post_parent'] ) && is_numeric( $r['post_parent'] ) ) { 
  35. bbp_update_forum( array( 
  36. 'forum_id' => $r['post_parent'],  
  37. 'post_parent' => get_post_field( 'post_parent', $r['post_parent'] ) 
  38. ) );