wp_check_comment_data_max_lengths example


    $allow_empty_comment = apply_filters( 'allow_empty_comment', false, $commentdata );
    if ( '' === $comment_content && ! $allow_empty_comment ) {
        return new WP_Error( 'require_valid_comment', __( '<strong>Error:</strong> Please type your comment text.' ), 200 );
    }

    $check_max_lengths = wp_check_comment_data_max_lengths( $commentdata );
    if ( is_wp_error( $check_max_lengths ) ) {
        return $check_max_lengths;
    }

    $comment_id = wp_new_comment( wp_slash( $commentdata ), true );
    if ( is_wp_error( $comment_id ) ) {
        return $comment_id;
    }

    if ( ! $comment_id ) {
        return new WP_Error( 'comment_save_error', __( '<strong>Error:</strong> The comment could not be saved. Please try again later.' ), 500 );
    }
$prepared_comment['comment_author_email'] = '';
        }

        if ( ! isset( $prepared_comment['comment_author_url'] ) ) {
            $prepared_comment['comment_author_url'] = '';
        }

        if ( ! isset( $prepared_comment['comment_agent'] ) ) {
            $prepared_comment['comment_agent'] = '';
        }

        $check_comment_lengths = wp_check_comment_data_max_lengths( $prepared_comment );

        if ( is_wp_error( $check_comment_lengths ) ) {
            $error_code = $check_comment_lengths->get_error_code();
            return new WP_Error(
                $error_code,
                __( 'Comment field exceeds maximum length allowed.' ),
                array( 'status' => 400 )
            );
        }

        $prepared_comment['comment_approved'] = wp_allow_comment( $prepared_comment, true );

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