bbp_check_for_duplicate

Check for duplicate topics/replies.

Description

bbp_check_for_duplicate( (array) $post_data = array() ); 

Check to make sure that a user is not making a duplicate post

Parameters (1)

0. $post_data — Optional. (array) => array()
Contains information about the comment

Usage

  1. if ( !function_exists( 'bbp_check_for_duplicate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3.  
  4. // Contains information about the comment 
  5. $post_data = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_check_for_duplicate($post_data); 
  9.  

Defined (1)

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

/includes/common/functions.php  
  1. function bbp_check_for_duplicate( $post_data = array() ) { 
  2.  
  3. // No duplicate checks for those who can throttle 
  4. if ( current_user_can( 'throttle' ) ) 
  5. return true; 
  6.  
  7. // Define global to use get_meta_sql() and get_var() methods 
  8. global $wpdb; 
  9.  
  10. // Parse arguments against default values 
  11. $r = bbp_parse_args( $post_data, array( 
  12. 'post_author' => 0,  
  13. 'post_type' => array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ),  
  14. 'post_parent' => 0,  
  15. 'post_content' => '',  
  16. 'post_status' => bbp_get_trash_status_id(),  
  17. 'anonymous_data' => false 
  18. ), 'check_for_duplicate' ); 
  19.  
  20. // Check for anonymous post 
  21. if ( empty( $r['post_author'] ) && ( !empty( $r['anonymous_data'] ) && !empty( $r['anonymous_data']['bbp_anonymous_email'] ) ) ) { 
  22. $clauses = get_meta_sql( array( array( 
  23. 'key' => '_bbp_anonymous_email',  
  24. 'value' => $r['anonymous_data']['bbp_anonymous_email'] 
  25. ) ), 'post', $wpdb->posts, 'ID' ); 
  26.  
  27. $join = $clauses['join']; 
  28. $where = $clauses['where']; 
  29. } else { 
  30. $join = $where = ''; 
  31.  
  32. // Unslash $r to pass through $wpdb->prepare() 
  33. // 
  34. // @see: http://bbpress.trac.wordpress.org/ticket/2185/ 
  35. // @see: http://core.trac.wordpress.org/changeset/23973/ 
  36. $r = function_exists( 'wp_unslash' ) ? wp_unslash( $r ) : stripslashes_deep( $r ); 
  37.  
  38. // Prepare duplicate check query 
  39. $query = $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s {$where}", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] ); 
  40. $query .= !empty( $r['post_parent'] ) ? $wpdb->prepare( " AND post_parent = %d", $r['post_parent'] ) : ''; 
  41. $query .= " LIMIT 1"; 
  42. $dupe = apply_filters( 'bbp_check_for_duplicate_query', $query, $r ); 
  43.  
  44. if ( $wpdb->get_var( $dupe ) ) { 
  45. do_action( 'bbp_check_for_duplicate_trigger', $post_data ); 
  46. return false; 
  47.  
  48. return true;