• In my blog users don’t need to be registered or logged in to comment. This means that anyone can comment in my name. How can I protect so only I can comment in my name?

Viewing 5 replies - 1 through 5 (of 5 total)
  • afaik there is no predefined function which does that but you can use function like this

    add_filter('pre_comment_author_name', 'protect_my_name');
    function protect_my_name( $name ){
      if( strolower($name) == 'my name' && !is_user_logged_in() ){
         wp_die(__('Booo, my name is not allowed'));
      }
      return $name;
    }

    Also, remember ‘my name’ after the ‘==’ should be in lower case and replace it with your name.

    Thread Starter drhur

    (@drhur)

    Thank you! Where should I add the code?

    functions.php in your theme folder and also some correction to the code above

    add_filter('pre_comment_author_name', 'protect_my_name');
    function protect_my_name( $name ){
      if( strtolower($name) == 'my name' && !is_user_logged_in() ){
         wp_die(__('Booo, my name is not allowed'));
      }
      return $name;
    }
    Thread Starter drhur

    (@drhur)

    Thank you, it worked! How do I add more names to the function?

    Use an array of names and check using in_array function.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Protect Admin Name in Comments’ is closed to new replies.