rest_pre_insert_comment
Filters a comment before it is inserted via the REST API.
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.
Usage
add_filter( 'rest_pre_insert_comment', 'wp_kama_rest_pre_insert_comment_filter', 10, 2 );
/**
* Function for `rest_pre_insert_comment` filter-hook.
*
* @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.
*
* @return array|WP_Error
*/
function wp_kama_rest_pre_insert_comment_filter( $prepared_comment, $request ){
// filter...
return $prepared_comment;
}
- $prepared_comment(array|WP_Error)
- The prepared comment data for wp_insert_comment().
- $request(WP_REST_Request)
- Request used to insert the comment.
Changelog
| Since 4.7.0 | Introduced. |
| Since 4.8.0 | $prepared_comment can now be a WP_Error to short-circuit insertion. |
Where the hook is called
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php 788
$prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request );