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
579            * Returning a WP_Error value from the filter will shortcircuit insertion and allow
580            * skipping further processing.
581            *
582            * @since 4.7.0
583            * @since 4.8.0 $prepared_comment can now be a WP_Error to shortcircuit insertion.
584            *
585            * @param array|WP_Error  $prepared_comment The prepared comment data for wp_insert_comment().
586            * @param WP_REST_Request $request          Request used to insert the comment.
587            */
588           $prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment, $request );
589           if ( is_wp_error( $prepared_comment ) ) {
590                return $prepared_comment;
591           }
592
593           $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) );
594
595           if ( ! $comment_id ) {
596                return new WP_Error( 'rest_comment_failed_create', __( 'Creating comment failed.' ), array( 'status' => 500 ) );
597           }