rest_pre_insert_comment WordPress Filter Hook

The rest_pre_insert_comment WordPress hook is triggered before a comment is inserted into the database. This hook can be used to perform any actions that need to be done before a comment is inserted, such as validating the comment or setting the comment_approved field.

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

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.


Top ↑

Parameters

$prepared_comment

(array|WP_Error)The prepared comment data for wp_insert_comment().

$request

(WP_REST_Request)Request used to insert the comment.


Top ↑

Source

File: wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

View on Trac



Top ↑

Changelog

Changelog
VersionDescription
4.8.0$prepared_comment can now be a WP_Error to short-circuit insertion.
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.