Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
497 views
in Plugins by

I want to block comments which include "*http*"

How to block post contain specific keywords or website?

1 Answer

0 votes
by
selected by
 
Best answer

Your filter comment could be something like this:

public function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment)

 {

 if (preg_match("/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/",$comment['content'])){

 $errors['content'] = 'You can not include url in comments!';
 }
 }
by
class qa_block_spam
{
   
    public function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment)

     {
   
                $errors['content'] = 'You can not include url in comments!';
                die();
by
edited by
it did not work :( nothing happens

i removed if statement for testing purposes
by
It works for me. If you enter a link like https://www.question2answer.org then the comment will not be added and the error will be displayed.
...