wp_blacklist_check

Does comment contain blacklisted characters or words.

Description

wp_blacklist_check( (string) $author, (string) $email, (string) $url, (string) $comment, (string) $user_ip, (string) $user_agent ); 

Parameters (6)

0. $author (string)
The author of the comment
1. $email (string)
The email of the comment
2. $url (string)
The url used in the comment
3. $comment (string)
The comment content
4. $user_ip (string)
The comment author IP address
5. $user_agent (string)
The author's browser user agent

Usage

  1. if ( !function_exists( 'wp_blacklist_check' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment.php'; 
  3.  
  4. // The author of the comment 
  5. $author = ''; 
  6.  
  7. // The email of the comment 
  8. $email = ''; 
  9.  
  10. // The url used in the comment 
  11. $url = ''; 
  12.  
  13. // The comment content 
  14. $comment = ''; 
  15.  
  16. // The comment author IP address 
  17. $user_ip = ''; 
  18.  
  19. // The author's browser user agent 
  20. $user_agent = ''; 
  21.  
  22. // NOTICE! Understand what this does before running. 
  23. $result = wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent); 
  24.  

Defined (1)

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

/wp-includes/comment.php  
  1. function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) { 
  2. /** 
  3. * Fires before the comment is tested for blacklisted characters or words. 
  4. * @since 1.5.0 
  5. * @param string $author Comment author. 
  6. * @param string $email Comment author's email. 
  7. * @param string $url Comment author's URL. 
  8. * @param string $comment Comment content. 
  9. * @param string $user_ip Comment author's IP address. 
  10. * @param string $user_agent Comment author's browser user agent. 
  11. */ 
  12. do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent ); 
  13.  
  14. $mod_keys = trim( get_option('blacklist_keys') ); 
  15. if ( '' == $mod_keys ) 
  16. return false; // If moderation keys are empty 
  17.  
  18. // Ensure HTML tags are not being used to bypass the blacklist. 
  19. $comment_without_html = wp_strip_all_tags( $comment ); 
  20.  
  21. $words = explode("\n", $mod_keys ); 
  22.  
  23. foreach ( (array) $words as $word ) { 
  24. $word = trim($word); 
  25.  
  26. // Skip empty lines 
  27. if ( empty($word) ) { continue; } 
  28.  
  29. // Do some escaping magic so that '#' chars in the 
  30. // spam words don't break things: 
  31. $word = preg_quote($word, '#'); 
  32.  
  33. $pattern = "#$word#i"; 
  34. if ( 
  35. preg_match($pattern, $author) 
  36. || preg_match($pattern, $email) 
  37. || preg_match($pattern, $url) 
  38. || preg_match($pattern, $comment) 
  39. || preg_match($pattern, $comment_without_html) 
  40. || preg_match($pattern, $user_ip) 
  41. || preg_match($pattern, $user_agent) 
  42. return true; 
  43. return false;