bbp_update_reply_walker

Walk up the ancestor tree from the current reply, and update all the counts.

Description

bbp_update_reply_walker( (int) $reply_id, (string) $last_active_time = '', (int) $forum_id = 0, (int) $topic_id = 0, (bool) $refresh = true ); 

Parameters (5)

0. $reply_id — Optional. (int)
Reply id
1. $last_active_time — Optional. (string) => ''
Last active time
2. $forum_id — Optional. (int)
Forum id
3. $topic_id — Optional. (int)
Topic id
4. $refresh — Optional. (bool) => true
If set to true, unsets all the previous parameters. Defaults to true

Usage

  1. if ( !function_exists( 'bbp_update_reply_walker' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/replies/functions.php'; 
  3.  
  4. // Optional. Reply id 
  5. $reply_id = -1; 
  6.  
  7. // Optional. Last active time 
  8. $last_active_time = ''; 
  9.  
  10. // Optional. Forum id 
  11. $forum_id = -1; 
  12.  
  13. // Optional. Topic id 
  14. $topic_id = -1; 
  15.  
  16. // If set to true, unsets all the previous parameters. 
  17. // Defaults to true 
  18. $refresh = true; 
  19.  
  20. // NOTICE! Understand what this does before running. 
  21. $result = bbp_update_reply_walker($reply_id, $last_active_time, $forum_id, $topic_id, $refresh); 
  22.  

Defined (1)

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

/includes/replies/functions.php  
  1. function bbp_update_reply_walker( $reply_id, $last_active_time = '', $forum_id = 0, $topic_id = 0, $refresh = true ) { 
  2.  
  3. // Verify the reply ID 
  4. $reply_id = bbp_get_reply_id( $reply_id ); 
  5.  
  6. // Reply was passed 
  7. if ( !empty( $reply_id ) ) { 
  8.  
  9. // Get the topic ID if none was passed 
  10. if ( empty( $topic_id ) ) { 
  11. $topic_id = bbp_get_reply_topic_id( $reply_id ); 
  12.  
  13. // Get the forum ID if none was passed 
  14. if ( empty( $forum_id ) ) { 
  15. $forum_id = bbp_get_reply_forum_id( $reply_id ); 
  16.  
  17. // Set the active_id based on topic_id/reply_id 
  18. $active_id = empty( $reply_id ) ? $topic_id : $reply_id; 
  19.  
  20. // Setup ancestors array to walk up 
  21. $ancestors = array_values( array_unique( array_merge( array( $topic_id, $forum_id ), (array) get_post_ancestors( $topic_id ) ) ) ); 
  22.  
  23. // If we want a full refresh, unset any of the possibly passed variables 
  24. if ( true === $refresh ) 
  25. $forum_id = $topic_id = $reply_id = $active_id = $last_active_time = 0; 
  26.  
  27. // Walk up ancestors 
  28. if ( !empty( $ancestors ) ) { 
  29. foreach ( $ancestors as $ancestor ) { 
  30.  
  31. // Reply meta relating to most recent reply 
  32. if ( bbp_is_reply( $ancestor ) ) { 
  33. // @todo - hierarchical replies 
  34.  
  35. // Topic meta relating to most recent reply 
  36. } elseif ( bbp_is_topic( $ancestor ) ) { 
  37.  
  38. // Last reply and active ID's 
  39. bbp_update_topic_last_reply_id ( $ancestor, $reply_id ); 
  40. bbp_update_topic_last_active_id( $ancestor, $active_id ); 
  41.  
  42. // Get the last active time if none was passed 
  43. $topic_last_active_time = $last_active_time; 
  44. if ( empty( $last_active_time ) ) { 
  45. $topic_last_active_time = get_post_field( 'post_date', bbp_get_topic_last_active_id( $ancestor ) ); 
  46.  
  47. // Only update if reply is published 
  48. if ( bbp_is_reply_published( $reply_id ) ) { 
  49. bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time ); 
  50.  
  51. // Counts 
  52. bbp_update_topic_voice_count ( $ancestor ); 
  53. bbp_update_topic_reply_count ( $ancestor ); 
  54.  
  55. // Forum meta relating to most recent topic 
  56. } elseif ( bbp_is_forum( $ancestor ) ) { 
  57.  
  58. // Last topic and reply ID's 
  59. bbp_update_forum_last_topic_id( $ancestor, $topic_id ); 
  60. bbp_update_forum_last_reply_id( $ancestor, $reply_id ); 
  61.  
  62. // Last Active 
  63. bbp_update_forum_last_active_id( $ancestor, $active_id ); 
  64.  
  65. // Get the last active time if none was passed 
  66. $forum_last_active_time = $last_active_time; 
  67. if ( empty( $last_active_time ) ) { 
  68. $forum_last_active_time = get_post_field( 'post_date', bbp_get_forum_last_active_id( $ancestor ) ); 
  69.  
  70. // Only update if reply is published 
  71. if ( bbp_is_reply_published( $reply_id ) ) { 
  72. bbp_update_forum_last_active_time( $ancestor, $forum_last_active_time ); 
  73.  
  74. // Counts