Title: rest_pre_insert_comment
Published: December 6, 2016
Last modified: February 24, 2026

---

# apply_filters( ‘rest_pre_insert_comment’, array|WP_Error $prepared_comment, WP_REST_Request $request )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#wp--skip-link--target)

Filters a comment before it is inserted via the REST API.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#description)󠁿

Allows modification of the comment right before it is inserted via [wp_insert_comment()](https://developer.wordpress.org/reference/functions/wp_insert_comment/).

Returning a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)
value from the filter will short-circuit insertion and allow skipping further processing.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#parameters)󠁿

 `$prepared_comment`array|[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)

The prepared comment data for [wp_insert_comment()](https://developer.wordpress.org/reference/functions/wp_insert_comment/).

`$request`[WP_REST_Request](https://developer.wordpress.org/reference/classes/wp_rest_request/)

Request used to insert the comment.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#source)󠁿

    ```php
    $prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php#L780)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php#L780-L780)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Comments_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Creates a comment.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/rest_pre_insert_comment/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.8.0](https://developer.wordpress.org/reference/since/4.8.0/) | `$prepared_comment` can now be a [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) to short-circuit insertion. | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Frest_pre_insert_comment%2F)
before being able to contribute a note or feedback.