bbp_get_reply_ancestor_id

Return the reply's ancestor reply id.

Description

bbp_get_reply_ancestor_id( (int) $reply_id = 0 ); 

Parameters (1)

0. $reply_id — Optional. (int)
The reply id.

Usage

  1. if ( !function_exists( 'bbp_get_reply_ancestor_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/replies/template.php'; 
  3.  
  4. // The reply id. 
  5. $reply_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_get_reply_ancestor_id($reply_id); 
  9.  

Defined (1)

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

/includes/replies/template.php  
  1. function bbp_get_reply_ancestor_id( $reply_id = 0 ) { 
  2.  
  3. // Validation 
  4. $reply_id = bbp_get_reply_id( $reply_id ); 
  5. if ( empty( $reply_id ) ) 
  6. return false; 
  7.  
  8. // Find highest reply ancestor 
  9. $ancestor_id = $reply_id; 
  10. while ( $parent_id = bbp_get_reply_to( $ancestor_id ) ) { 
  11. if ( empty( $parent_id ) || ( $parent_id === $ancestor_id ) || ( bbp_get_reply_topic_id( $reply_id ) === $parent_id ) || ( $parent_id === $reply_id ) ) { 
  12. break; 
  13. $ancestor_id = $parent_id; 
  14.  
  15. return (int) $ancestor_id;