• How to disallow names in comments that look like the admin/author? If the nickname for the admin is “Sharkboy”, I don’t want people to call themselves “Sharkboy666” or something.

    I found something that almost does what I want. In the “Discussion Settings” you can have a comment moderation list or a blacklist. But this is also for the comment itself, which means people wouldn’t be able to mention “Sharkboy” in the comment. But that’s overkill, I just don’t want them to to post that in the “Name”-field.

    Anybody know how to do this?

Viewing 7 replies - 1 through 7 (of 7 total)
  • if someone mention “Sharkboy”, what is the result you like?

    Thread Starter wobblypop

    (@wobblypop)

    Nothing if it’s in the comment itself. I only want to disallow it in the “name” field.

    I am using open comments, so people don’t have to register. People just fill in their name, but it shouldn’t be “Sharkboy” because then people will think it’s the real author.

    Thread Starter wobblypop

    (@wobblypop)

    I can’t be the first person to want this, right? 😀

    I’m now thinking of editing the WordPress code to manually check submitted names if they contain our author’s names, but I’m afraid I will lose my changes when I update WordPress.

    I really wish there was a plug-in for this, or a bit more advanced settings in the “Discussion settings”.

    Hello, wobblypop, according to what you say, I think there are two solutions. Either you refuse the commentators which means their comment won’t be submitted, either their name will be changed, for instance, to anonymous automatically when the comment is submitted if the name filed contains “Sharkboy”.

    As for the second one, it can be done if we could find the right filter. Do you like the second solution?

    Thread Starter wobblypop

    (@wobblypop)

    Hi Hedonplay, thanks for taking the time to answer.

    I like the second idea best, just automatically changing the name to “Anonymous”. Do you think a plugin is already out there? I searched but couldn’t find one.

    I don’t mind coding one myself, but I don’t want to reinvent the wheel ofcourse!

    /*
    **change the comment author name if it contains any string that are disallowed, when saving a new comment in the database
    */
    if(is_author()){ //do not apply the filter if the author post a comment
    add_filter( 'preprocess_comment' , 'wh_change_comment_author' , '99' );
    }
    function wh_change_comment_author($commentdata)
    {
      $name_disallowed='sharkboy'; //you can change it as you need
      $name_default='anonymous';
      //the comment_author is contained in the array $commentdata
      if(stristr($commentdata['comment_author'],$name_disallowed)) {
    	$commentdata['comment_author']=$name_default; //replace the name disallowed by the default one
      }
    	return $commentdata;
    }

    add this piece of code to the function.php which is in your theme directory.

    Hopefully it works.

    Thread Starter wobblypop

    (@wobblypop)

    Hi Hedonplay,

    Thank you very much! I only changed the code slightly to get it to work (I moved the “is_author” check inside the function). This works perfectly! Thanks for the help, it’s much appreciated.

    /*
    **change the comment author name if it contains any string that are disallowed, when saving a new comment in the database
    */
    function wh_change_comment_author($commentdata)
    {
        if(!is_author())
        {
            $name_disallowed='sharkboy'; //you can change it as you need
            $name_default='anonymous';
            //the comment_author is contained in the array $commentdata
            if(stristr($commentdata['comment_author'],$name_disallowed)) {
                $commentdata['comment_author']=$name_default; //replace the name disallowed by the default one
            }
            return $commentdata;
        }
    }
    
    add_filter( 'preprocess_comment' , 'wh_change_comment_author' , '99' );
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to disallow names in comments that look like the admin/author?’ is closed to new replies.