wp_filter_comment example

public static function get_last_comment() {
        return self::$last_comment;
    }
    
    public static function set_last_comment( $comment ) {
        if ( is_null( $comment ) ) {
            self::$last_comment = null;
        }
        else {
            // We filter it here so that it matches the filtered comment data that we'll have to compare against later.             // wp_filter_comment expects comment_author_IP             self::$last_comment = wp_filter_comment(
                array_merge(
                    array( 'comment_author_IP' => self::get_ip_address() ),
                    $comment
                )
            );
        }
    }

    // this fires on wp_insert_comment. we can't update comment_meta when auto_check_comment() runs     // because we don't know the comment ID at that point.     public static function auto_check_update_meta( $id$comment ) {
        

        $prepared_comment = apply_filters( 'rest_pre_insert_comment', $prepared_comment$request );
        if ( is_wp_error( $prepared_comment ) ) {
            return $prepared_comment;
        }

        $comment_id = wp_insert_comment( wp_filter_comment( wp_slash( (array) $prepared_comment ) ) );

        if ( ! $comment_id ) {
            return new WP_Error(
                'rest_comment_failed_create',
                __( 'Creating comment failed.' ),
                array( 'status' => 500 )
            );
        }

        if ( isset( $request['status'] ) ) {
            $this->handle_status_param( $request['status']$comment_id );
        }
$commentdata['comment_date'] = current_time( 'mysql' );
    }

    if ( empty( $commentdata['comment_date_gmt'] ) ) {
        $commentdata['comment_date_gmt'] = current_time( 'mysql', 1 );
    }

    if ( empty( $commentdata['comment_type'] ) ) {
        $commentdata['comment_type'] = 'comment';
    }

    $commentdata = wp_filter_comment( $commentdata );

    $commentdata['comment_approved'] = wp_allow_comment( $commentdata$wp_error );

    if ( is_wp_error( $commentdata['comment_approved'] ) ) {
        return $commentdata['comment_approved'];
    }

    $comment_id = wp_insert_comment( $commentdata );

    if ( ! $comment_id ) {
        $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' );

        
Home | Imprint | This part of the site doesn't use cookies.