Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: rest_pre_insert_comment

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

Line Code
552            * Filters a comment before it is inserted via the REST API.
553            *
554            * Allows modification of the comment right before it is inserted via wp_insert_comment().
555            *
556            * @since 4.7.0
557            *
558            * @param array           $prepared_comment The prepared comment data for wp_insert_comment().
559            * @param WP_REST_Request $request          Request used to insert the comment.
560            */
561           $prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request );
562
563           $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) );
564
565           if ( ! $comment_id ) {
566                return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) );
567           }
568
569           if ( isset( $request['status'] ) ) {
570                $this->handle_status_param( $request['status'], $comment_id );