bbp_update_reply_topic_id

Update the reply with its topic id it is in.

Description

bbp_update_reply_topic_id( (int) $reply_id = 0, (int) $topic_id = 0 ); 

Parameters (2)

0. $reply_id — Optional. (int)
Reply id to update
1. $topic_id — Optional. (int)
Topic id

Usage

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

Defined (1)

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

/includes/replies/functions.php  
  1. function bbp_update_reply_topic_id( $reply_id = 0, $topic_id = 0 ) { 
  2.  
  3. // Validation 
  4. $reply_id = bbp_get_reply_id( $reply_id ); 
  5. $topic_id = bbp_get_topic_id( $topic_id ); 
  6.  
  7. // If no topic_id was passed, walk up ancestors and look for topic type 
  8. if ( empty( $topic_id ) ) { 
  9.  
  10. // Get ancestors 
  11. $ancestors = (array) get_post_ancestors( $reply_id ); 
  12.  
  13. // Loop through ancestors 
  14. if ( !empty( $ancestors ) ) { 
  15. foreach ( $ancestors as $ancestor ) { 
  16.  
  17. // Get first parent that is a forum 
  18. if ( get_post_field( 'post_type', $ancestor ) === bbp_get_topic_post_type() ) { 
  19. $topic_id = $ancestor; 
  20.  
  21. // Found a forum, so exit the loop and continue 
  22. continue; 
  23.  
  24. // Update the topic ID 
  25. bbp_update_topic_id( $reply_id, $topic_id ); 
  26.  
  27. return apply_filters( 'bbp_update_reply_topic_id', (int) $topic_id, $reply_id );