评论是否包含列入黑名单的字符或单词。

原型

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

参数

$author (string) (Required) 评论的作者

$email (string) (Required) 评论的电子邮件

$url (string) (Required) 评论中使用的网址

$comment (string) (Required) 评论内容

$user_ip (string) (Required) 评论作者的IP地址

$user_agent (string) (Required) 作者的浏览器用户代理

返回值

(bool)  如果评论包含列入黑名单的内容,则为True;如果评论不包含,则为false

源文件

路径:wp-includes/comment.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
...
function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
	/**
	 * Fires before the comment is tested for blacklisted characters or words.
	 *
	 * @since 1.5.0
	 *
	 * @param string $author     Comment author.
	 * @param string $email      Comment author's email.
	 * @param string $url        Comment author's URL.
	 * @param string $comment    Comment content.
	 * @param string $user_ip    Comment author's IP address.
	 * @param string $user_agent Comment author's browser user agent.
	 */
	do_action( 'wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent );

	$mod_keys = trim( get_option('blacklist_keys') );
	if ( '' == $mod_keys )
		return false; // If moderation keys are empty

	// Ensure HTML tags are not being used to bypass the blacklist.
	$comment_without_html = wp_strip_all_tags( $comment );

	$words = explode("\n", $mod_keys );

	foreach ( (array) $words as $word ) {
		$word = trim($word);

		// Skip empty lines
		if ( empty($word) ) { continue; }

		// Do some escaping magic so that '#' chars in the
		// spam words don't break things:
		$word = preg_quote($word, '#');

		$pattern = "#$word#i";
		if (
			   preg_match($pattern, $author)
			|| preg_match($pattern, $email)
			|| preg_match($pattern, $url)
			|| preg_match($pattern, $comment)
			|| preg_match($pattern, $comment_without_html)
			|| preg_match($pattern, $user_ip)
			|| preg_match($pattern, $user_agent)
		 )
			return true;
	}
	return false;
}

...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_blacklist_check/