bbp_check_for_blacklist

Checks topics and replies against the discussion blacklist of blocked keys.

Description

bbp_check_for_blacklist( (constant) $anonymous_data = false, (int) $author_id = 0, (string) $title = '', (string) $content = '' ); 

Parameters (4)

0. $anonymous_data — Optional. (constant) => false
The anonymous data.
1. $author_id — Optional. (int)
Topic or reply author ID
2. $title — Optional. (string) => ''
The title of the content
3. $content — Optional. (string) => ''
The content being posted

Usage

  1. if ( !function_exists( 'bbp_check_for_blacklist' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/common/functions.php'; 
  3.  
  4. // The anonymous data. 
  5. $anonymous_data = false; 
  6.  
  7. // Topic or reply author ID 
  8. $author_id = -1; 
  9.  
  10. // The title of the content 
  11. $title = ''; 
  12.  
  13. // The content being posted 
  14. $content = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bbp_check_for_blacklist($anonymous_data, $author_id, $title, $content); 
  18.  

Defined (1)

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

/includes/common/functions.php  
  1. function bbp_check_for_blacklist( $anonymous_data = false, $author_id = 0, $title = '', $content = '' ) { 
  2.  
  3. // Allow for blacklist check to be skipped 
  4. if ( apply_filters( 'bbp_bypass_check_for_blacklist', false, $anonymous_data, $author_id, $title, $content ) ) 
  5. return true; 
  6.  
  7. // Bail if keymaster is author 
  8. if ( !empty( $author_id ) && bbp_is_user_keymaster( $author_id ) ) 
  9. return true; 
  10.  
  11. // Define local variable 
  12. $_post = array(); 
  13.  
  14. /** Blacklist *************************************************************/ 
  15.  
  16. // Get the moderation keys 
  17. $blacklist = trim( get_option( 'blacklist_keys' ) ); 
  18.  
  19. // Bail if blacklist is empty 
  20. if ( empty( $blacklist ) ) 
  21. return true; 
  22.  
  23. /** User Data *************************************************************/ 
  24.  
  25. // Map anonymous user data 
  26. if ( !empty( $anonymous_data ) ) { 
  27. $_post['author'] = $anonymous_data['bbp_anonymous_name']; 
  28. $_post['email'] = $anonymous_data['bbp_anonymous_email']; 
  29. $_post['url'] = $anonymous_data['bbp_anonymous_website']; 
  30.  
  31. // Map current user data 
  32. } elseif ( !empty( $author_id ) ) { 
  33.  
  34. // Get author data 
  35. $user = get_userdata( $author_id ); 
  36.  
  37. // If data exists, map it 
  38. if ( !empty( $user ) ) { 
  39. $_post['author'] = $user->display_name; 
  40. $_post['email'] = $user->user_email; 
  41. $_post['url'] = $user->user_url; 
  42.  
  43. // Current user IP and user agent 
  44. $_post['user_ip'] = bbp_current_author_ip(); 
  45. $_post['user_ua'] = bbp_current_author_ua(); 
  46.  
  47. // Post title and content 
  48. $_post['title'] = $title; 
  49. $_post['content'] = $content; 
  50.  
  51. /** Words *****************************************************************/ 
  52.  
  53. // Get words separated by new lines 
  54. $words = explode( "\n", $blacklist ); 
  55.  
  56. // Loop through words 
  57. foreach ( (array) $words as $word ) { 
  58.  
  59. // Trim the whitespace from the word 
  60. $word = trim( $word ); 
  61.  
  62. // Skip empty lines 
  63. if ( empty( $word ) ) { continue; } 
  64.  
  65. // Do some escaping magic so that '#' chars in the 
  66. // spam words don't break things: 
  67. $word = preg_quote( $word, '#' ); 
  68. $pattern = "#$word#i"; 
  69.  
  70. // Loop through post data 
  71. foreach ( $_post as $post_data ) { 
  72.  
  73. // Check each user data for current word 
  74. if ( preg_match( $pattern, $post_data ) ) { 
  75.  
  76. // Post does not pass 
  77. return false; 
  78.  
  79. // Check passed successfully 
  80. return true;