apply_filters( 'rest_pre_insert_comment', array|WP_Error $prepared_comment, WP_REST_Request $request )
- Since
- 4.7.0, 4.8.0
Filters a comment before it is inserted via the REST API.
Description
Allows modification of the comment right before it is inserted via wp_insert_comment().
Returning a WP_Error value from the filter will short-circuit insertion and allow skipping further processing.
Compatibility
- WordPress
- since 4.8.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Parameters
$prepared_commentarray|WP_Error- The prepared comment data for wp_insert_comment().
$requestWP_REST_Request- Request used to insert the comment.
Where this hook fires · 1
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:788WP_REST_Comments_Controller::create_item()
Source code
* @since 4.7.0 * @since 4.8.0 `$prepared_comment` can now be a WP_Error to short-circuit insertion. * * @param array|WP_Error $prepared_comment The prepared comment data for wp_insert_comment(). * @param WP_REST_Request $request Request used to insert the comment. */ $prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request ); if ( is_wp_error( $prepared_comment ) ) { return $prepared_comment; } $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) );Changelog
Introduced in 4.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
4.8.0
$prepared_comment can now be a WP_Error to short-circuit insertion.from the docblock4.7.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
- Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.