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.
(@drhur)
15 years, 3 months ago
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?