wp_filter_comment

函数
wp_filter_comment ( $commentdata )
参数
  • (array) $commentdata Contains information on the comment.
    Required:
返回值
  • (array) Parsed comment information.
定义位置
相关方法
wp_insert_commentwp_delete_commentwp_list_commentswp_trash_commentwp_filter_content_tags
引入
2.0.0
弃用
-

wp_filter_comment。这个过滤器用于在显示评论对象之前修改它。它把评论对象作为一个参数,并返回修改后的评论对象。

对评论数据进行过滤和净化。

完成后将评论数据”过滤”字段设置为真。这可以检查评论是否应该被过滤,并防止同一评论被多次过滤。

function wp_filter_comment( $commentdata ) {
	if ( isset( $commentdata['user_ID'] ) ) {
		/**
		 * Filters 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'] );
	}

	/**
	 * Filters the comment author's browser user agent before it is set.
	 *
	 * @since 1.5.0
	 *
	 * @param string $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'] );
	/**
	 * Filters the comment content before it is set.
	 *
	 * @since 1.5.0
	 *
	 * @param string $comment_content The comment content.
	 */
	$commentdata['comment_content'] = apply_filters( 'pre_comment_content', $commentdata['comment_content'] );
	/**
	 * Filters the comment author's IP address before it is set.
	 *
	 * @since 1.5.0
	 *
	 * @param string $comment_author_ip The comment author's IP address.
	 */
	$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;
}

常见问题

FAQs
查看更多 >