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