wp_filter_comment()过滤一个评论信息

目录

描述

译文

过滤审查评论资料。

完成后将评论资料'filtered'字段设为true。这一动作可判断评论是否应被过滤,以及是否应该阻止同一评论被多次过滤。

原文

Filters and sanitizes comment data.

Sets the comment data 'filtered' field to true when finished. This can be checked as to whether the comment should be filtered and to keep from filtering the same comment more than once.

wp_filter_comment() 描述

用法

<?php wp_filter_comment$commentdata ?>

wp_filter_comment() 用法

参数

$commentdata

(array) (必填) Contains information on the comment.

默认值: None

wp_filter_comment() 参数

返回值

(array) 

Parsed comment information.

wp_filter_comment() 返回值

注意

  • 使用到: apply_filters() 调用 'pre_user_id' hook on comment author's user ID
  • 使用到: apply_filters() 调用 'pre_comment_user_agent' hook on comment author's user agent
  • 使用到: apply_filters() 调用 'pre_comment_author_name' hook on comment author's name
  • 使用到: apply_filters() 调用 'pre_comment_content' hook on the comment's content
  • 使用到: apply_filters() 调用 'pre_comment_user_ip' hook on comment author's IP
  • 使用到: apply_filters() 调用 'pre_comment_author_url' hook on comment author's URL
  • 使用到: apply_filters() 调用 'pre_comment_author_email' hook on comment author's email address

wp_filter_comment() 注意

历史

添加于 版本: 2.0.0

wp_filter_comment() 历史

源文件

wp_filter_comment() 函数的代码位于 wp-includes/comment.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Filters and sanitizes comment data.
 *
 * Sets the comment data 'filtered' field to true when finished. This can be
 * checked as to whether the comment should be filtered and to keep from
 * filtering the same comment more than once.
 *
 * @since 2.0.0
 *
 * @param array $commentdata Contains information on the comment.
 * @return array Parsed comment information.
 */
function wp_filter_comment($commentdata) {
	if ( isset( $commentdata['user_ID'] ) ) {
		/**
		 * Filter the comment author's user id before it is set.
		 *
		 * The first time this filter is evaluated, 'user_ID' is checked
		 * (for back-compat), followed by the standard 'user_id' value.
		 *
		 * @since 1.5.0
		 *
		 * @param int $user_ID The comment author's user ID.
		 */
		$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] );
	} elseif ( isset( $commentdata['user_id'] ) ) {
		/** This filter is documented in wp-includes/comment.php */
		$commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_id'] );
	}

	/**
	 * Filter the comment author's browser user agent before it is set.
	 *
	 * @since 1.5.0
	 *
	 * @param int $comment_agent The comment author's browser user agent.
	 */
	$commentdata['comment_agent'] = apply_filters( 'pre_comment_user_agent', ( isset( $commentdata['comment_agent'] ) ? $commentdata['comment_agent'] : '' ) );
	/** This filter is documented in wp-includes/comment.php */
	$commentdata['comment_author'] = apply_filters( 'pre_comment_author_name', $commentdata['comment_author'] );
	/**
	 * Filter the comment content before it is set.
	 *
	 * @since 1.5.0
	 *
	 * @param int $comment_content The comment content.
	 */
	$commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] );
	/**
	 * Filter the comment author's IP before it is set.
	 *
	 * @since 1.5.0
	 *
	 * @param int $comment_author_ip The comment author's IP.
	 */
	$commentdata['comment_author_IP'] = apply_filters( 'pre_comment_user_ip', $commentdata['comment_author_IP'] );
	/** This filter is documented in wp-includes/comment.php */
	$commentdata['comment_author_url'] = apply_filters( 'pre_comment_author_url', $commentdata['comment_author_url'] );
	/** This filter is documented in wp-includes/comment.php */
	$commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] );
	$commentdata['filtered'] = true;
	return $commentdata;
}

wp_filter_comment() 源文件

相关