返回介绍

wp_blacklist_check()

发布于 2017-09-11 11:34:44 字数 3302 浏览 1014 评论 0 收藏 0

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

Does comment contain blacklisted characters or words.


description


参数

$author

(string) (Required) The author of the comment

$email

(string) (Required) The email of the comment

$url

(string) (Required) The url used in the comment

$comment

(string) (Required) The comment content

$user_ip

(string) (Required) The comment author IP address

$user_agent

(string) (Required) The author's browser user agent


返回值

(bool) True if comment contains blacklisted content, false if comment does not


源代码

File: wp-includes/comment.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;
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/formatting.php: wp_strip_all_tags()
  • wp-includes/plugin.php: do_action()
  • wp-includes/option.php: get_option()
  • wp-includes/comment.php: wp_blacklist_check

Used By

  • wp-includes/comment.php: wp_allow_comment()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文