bbp_update_reply_forum_id

Update the reply with its forum id it is in.

Description

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

Parameters (2)

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

Usage

  1. if ( !function_exists( 'bbp_update_reply_forum_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. Forum id 
  8. $forum_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_update_reply_forum_id($reply_id, $forum_id); 
  12.  

Defined (1)

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

/includes/replies/functions.php  
  1. function bbp_update_reply_forum_id( $reply_id = 0, $forum_id = 0 ) { 
  2.  
  3. // Validation 
  4. $reply_id = bbp_get_reply_id( $reply_id ); 
  5. $forum_id = bbp_get_forum_id( $forum_id ); 
  6.  
  7. // If no forum_id was passed, walk up ancestors and look for forum type 
  8. if ( empty( $forum_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_forum_post_type() ) { 
  19. $forum_id = $ancestor; 
  20.  
  21. // Found a forum, so exit the loop and continue 
  22. continue; 
  23.  
  24. // Update the forum ID 
  25. bbp_update_forum_id( $reply_id, $forum_id ); 
  26.  
  27. return apply_filters( 'bbp_update_reply_forum_id', (int) $forum_id, $reply_id );