bp_forums_reply_exists

Check to see whether a user has already left this particular reply on a given post.

Description

bp_forums_reply_exists( (string) $text = '', (int) $topic_id = 0, (int) $user_id = 0 ); 

Used to prevent dupes.

Parameters (3)

0. $text — Optional. (string) => ''
The text of the comment.
1. $topic_id — Optional. (int)
The topic id.
2. $user_id — Optional. (int)
The user id.

Usage

  1. if ( !function_exists( 'bp_forums_reply_exists' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bp-forums-functions.php'; 
  3.  
  4. // The text of the comment. 
  5. $text = ''; 
  6.  
  7. // The topic id. 
  8. $topic_id = -1; 
  9.  
  10. // The user id. 
  11. $user_id = -1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bp_forums_reply_exists($text, $topic_id, $user_id); 
  15.  

Defined (1)

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

/bp-forums/bp-forums-functions.php  
  1. function bp_forums_reply_exists( $text = '', $topic_id = 0, $user_id = 0 ) { 
  2.  
  3. $reply_exists = false; 
  4.  
  5. if ( $text && $topic_id && $user_id ) { 
  6.  
  7. /** This action is documented in bp-forums/bp-forums-screens.php */ 
  8.  
  9. $args = array( 
  10. 'post_author_id' => $user_id,  
  11. 'topic_id' => $topic_id 
  12. ); 
  13.  
  14. // Set the reply_exists_text so we can check it in the filter below. 
  15. buddypress)->forums->reply_exists_text = $text; 
  16.  
  17. // BB_Query's post_text parameter does a MATCH, while we need exact matches. 
  18. $query = new BB_Query( 'post', $args ); 
  19.  
  20. // Cleanup. 
  21. unset(buddypress)->forums->reply_exists_text ); 
  22.  
  23. $reply_exists = (bool) !empty( $query->results ); 
  24.  
  25. /** 
  26. * Filters whether a user has already left this particular reply on a given post. 
  27. * @since 1.6.0 
  28. * @param bool $reply_exists Whether or not a reply exists. 
  29. * @param string $text The text of the comment. 
  30. * @param int $topic_id The topic ID. 
  31. * @param int $user_id The user ID. 
  32. */ 
  33. return (bool) apply_filters( 'bp_forums_reply_exists', $reply_exists, $text, $topic_id, $user_id );