I've got my discussion settings set to allow people to comment without registering, so the comment form has the standard Name, Email, Website and Comment, and this is working exactly as I want.

The only problem is that if someone uses an admin's screenname and email, it looks as though the comment has come from the admin, as it picks up the gravitar and all.

Is there any way to prevent users commenting with an email that matches an admins - unless it is the admin, in which case they'd be logged in?

Or do I just have to moderate every comment before it's published?

  • 1
    I would suggest that you moderate comments, and get a good recaptha plugin and something like akismet to secure your comment form. Comment spam is the biggest form of spam on any blog. Your comment form might work great now, until spambots pick it up, then you'll recieve hundreds of spam comments a day Aug 13, 2014 at 12:14

2 Answers 2


All you need is to simply check if the entered name or email matched any admin accounts before the comment is saved.

function restrict_admin_names() {
    if ( !is_user_logged_in() ) {
        $name = $_POST['author']; // Get Submitted Name
        $email = $_POST['email']; // Get Submitted Email
        $admins = get_super_admins(); // Get an array of admin login
        $adminemail[] = ''; // Create an empty array of admin emails
        $admindisplayname[] = ''; // Create an empty array of admin display names

            // Create an array of admin emails and display names
            foreach ($admins as $admin) {
                $userdata = get_user_by( 'login', $admin );
                $adminemail[] = $userdata->user_email;
                $admindisplayname[] = $userdata->display_name;

        if ( isset($name) && in_array( $name, $admins) && in_array( $name, $admindisplayname) ) {
            wp_die( __('Sorry, you can not use that name', 'mytextdomain' ) );

        if ( isset($email) && in_array( $email, $adminemail) ) {
            wp_die( __('Sorry, you can not use that email', 'mytextdomain' ) );
add_action('pre_comment_on_post', 'restrict_admin_names');

Though it just checks for admins, but you can modify the code to check for any user roles or all the registered users.

Needless to say, this code goes into your theme's functions.php file.


I think that the only way is moderate your comments or require user registration. Another solution could be install jetpack and let your users use their wordpress.com username (this can avoid registration in many cases). Another Trick that you can use to avoid spambot lets comment on old posts is close the comments about a post after n days

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.