bbp_check_for_moderation

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

Description

bbp_check_for_moderation( (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_moderation' ) ) { 
  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_moderation($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_moderation( $anonymous_data = false, $author_id = 0, $title = '', $content = '' ) { 
  2.  
  3. // Allow for moderation check to be skipped 
  4. if ( apply_filters( 'bbp_bypass_check_for_moderation', 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(s) 
  12. $_post = array(); 
  13. $match_out = ''; 
  14.  
  15. /** Blacklist *************************************************************/ 
  16.  
  17. // Get the moderation keys 
  18. $blacklist = trim( get_option( 'moderation_keys' ) ); 
  19.  
  20. // Bail if blacklist is empty 
  21. if ( empty( $blacklist ) ) 
  22. return true; 
  23.  
  24. /** User Data *************************************************************/ 
  25.  
  26. // Map anonymous user data 
  27. if ( !empty( $anonymous_data ) ) { 
  28. $_post['author'] = $anonymous_data['bbp_anonymous_name']; 
  29. $_post['email'] = $anonymous_data['bbp_anonymous_email']; 
  30. $_post['url'] = $anonymous_data['bbp_anonymous_website']; 
  31.  
  32. // Map current user data 
  33. } elseif ( !empty( $author_id ) ) { 
  34.  
  35. // Get author data 
  36. $user = get_userdata( $author_id ); 
  37.  
  38. // If data exists, map it 
  39. if ( !empty( $user ) ) { 
  40. $_post['author'] = $user->display_name; 
  41. $_post['email'] = $user->user_email; 
  42. $_post['url'] = $user->user_url; 
  43.  
  44. // Current user IP and user agent 
  45. $_post['user_ip'] = bbp_current_author_ip(); 
  46. $_post['user_ua'] = bbp_current_author_ua(); 
  47.  
  48. // Post title and content 
  49. $_post['title'] = $title; 
  50. $_post['content'] = $content; 
  51.  
  52. /** Max Links *************************************************************/ 
  53.  
  54. $max_links = get_option( 'comment_max_links' ); 
  55. if ( !empty( $max_links ) ) { 
  56.  
  57. // How many links? 
  58. $num_links = preg_match_all( '/<a [^>]*href/i', $content, $match_out ); 
  59.  
  60. // Allow for bumping the max to include the user's URL 
  61. $num_links = apply_filters( 'comment_max_links_url', $num_links, $_post['url'] ); 
  62.  
  63. // Das ist zu viele links! 
  64. if ( $num_links >= $max_links ) { 
  65. return false; 
  66.  
  67. /** Words *****************************************************************/ 
  68.  
  69. // Get words separated by new lines 
  70. $words = explode( "\n", $blacklist ); 
  71.  
  72. // Loop through words 
  73. foreach ( (array) $words as $word ) { 
  74.  
  75. // Trim the whitespace from the word 
  76. $word = trim( $word ); 
  77.  
  78. // Skip empty lines 
  79. if ( empty( $word ) ) { continue; } 
  80.  
  81. // Do some escaping magic so that '#' chars in the 
  82. // spam words don't break things: 
  83. $word = preg_quote( $word, '#' ); 
  84. $pattern = "#$word#i"; 
  85.  
  86. // Loop through post data 
  87. foreach ( $_post as $post_data ) { 
  88.  
  89. // Check each user data for current word 
  90. if ( preg_match( $pattern, $post_data ) ) { 
  91.  
  92. // Post does not pass 
  93. return false; 
  94.  
  95. // Check passed successfully 
  96. return true;