Creating a plugin to sanitize comment and the url field before display only

I want to create a plugin to sanitize comment and mainly the url field before display only (not before adding to database), to filter the url fields and only allow displaying this field only if it contains specific data, otherwise I want to replace this url field with something safe or clear it.

( i do not want users to enter the url as “test.com” or “example.com” , i want to remove it in these cases)

Read More

How can I do that, which filter do i need to add to ?

EDIT:

based on the selected answer, I created this plugin to reset all urls to empty strings:

<?php
/*
Plugin Name: Get rid of websites before display
*/
function my_custom_remove_website( $comments ) {
    foreach ($comments as $k => $comment) {
        $comments[$k]->comment_author_url = "";
    }
    return $comments;
}
add_filter( 'comments_array', 'my_custom_remove_website' );

Please feel free to comment or answer if this plugin is not done with best practices.

Related posts

Leave a Reply

1 comment

  1. You might want to check out the comments_array filter.

    In 3.5, it is applied in Line 891 of wp-includes/comment-template.php:
    $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );