# wp_filter_comment()

URL: https://chugunov.pro/api-wordpress/functions/wp_filter_comment/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.0.0.

## Сигнатура

```php
wp_filter_comment( array $commentdata ): array
```

## Описание

По завершении устанавливает поле 'filtered' данных комментария в true. По нему можно проверить, нужно ли фильтровать комментарий, и избежать повторной фильтрации одного и того же комментария.

## Параметры

- `$commentdata` `array` — обязательный. Содержит информацию о комментарии.

## Возвращаемое значение

`array`

## Исходный код

Файл: `wp-includes/comment.php:2193`

```php
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', ( $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;
}
```

## История изменений

- 2.0.0 — Introduced.

## Связанные

Использует: [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: `WP_REST_Comments_Controller::create_item`, [`wp_new_comment`](https://chugunov.pro/api-wordpress/functions/wp_new_comment/), [`wp_update_comment`](https://chugunov.pro/api-wordpress/functions/wp_update_comment/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_filter_comment/
