Welcome to Dagon Design. In addition to free scripts, WordPress plugins, and articles, we offer a variety of services including custom theme design, plugin creation, and PHP scripting. Contact me for more information.

Updated Friday, February 20th, 2009 at 8:20pm

Prevent author impersonation in WordPress comments

This modification to WordPress prevents unregistered comment authors from using the names or email addresses of the registered authors on your site. It does this by first checking to see if the comment author is logged in. If they are not, it compares their name and email address to the registered author data. If there is a match, the comment is blocked and a custom message is displayed. The name and email address comparison is case-insensitive.

Requirements

This code modification has been tested in WordPress 2.2 through 2.8+

Instructions

1) Open /wp-comments-post.php for editing (backup the file first!)

2) Find the following block of code:

Notice: In WordPress 2.8, the code has changed a bit, but should be easy to find near the top of the page.

$comment_author       = trim(strip_tags($_POST['author']));
$comment_author_email = trim($_POST['email']);
$comment_author_url   = trim($_POST['url']);
$comment_content      = trim($_POST['comment']);

3) After it, add the following:

// get list of user (display) names for blog
global $wpdb;
$valid_users = (array)$wpdb->get_results("
  SELECT display_name, user_email FROM " . $wpdb->prefix . "users");

// get ID of logged in user (if there is one)
global $userdata;
get_currentuserinfo();
$logged_in_name = $userdata->ID;
$logged_in_email = $userdata->user_email;
 
// see if the comment author matches an existing author
$found_match = FALSE;
foreach ($valid_users as $va) {
  if (trim($va->display_name) != '') {
    if (strtolower($va->display_name) == strtolower($comment_author)) {
      $found_match = TRUE;
      break;
    }
  }
  if (trim($va->user_email) != '') {
    if (strtolower($va->user_email) == strtolower($comment_author_email)) {
      $found_match = TRUE;
      break;
    }
  }  
}

// if commenter is not logged in, but match was found, block the comment
if (trim($logged_in_name) == '') {
  if ($found_match == TRUE) {
    wp_die( __('You cannot post using the name or email of a registered author.') );
  }
}

4) Save and close the file

Notes

To test this modification, simply log out and try to post a comment using the name that displays when you regularly post comments (when you are logged in).

If you would like to change the message, just modify this line:

wp_die( __('You cannot post using the name or email of a registered author.') );

  If you have found this page useful, please consider donating. Thanks!

Pages: « 6 5 4 [3] 2 1 » Show All

  1. Wow , I was looking for this tips until i found this
    It’s very nice tips.masters degree sports management

  2. yes agree with people. This is the nice tip we should know. Go Go

  3. please read through the comments because most common issues have already been discussed many times. Thanks.healthcare administration degree online

  4. Thanks so much! Great plugin.
    mp4 to dvd, itunes to dvd

  5. Thank you thank this ia a nice tip

  6. 40
    person_guyz

    Best-of-Programm jedoch probiert Josef Hader etwas, was viele Kollegen machen, er aber normalerweise nicht: Nummern spielen und dazwischen Lieder singen.online engineering masters degrees

  7. 39
    jibran

    Companies these days are using ergonomic furniture to ensure that there are no injuries from work related hazards. Use an ergonomic chair and feel better comfort in your back and shoulder. Bed Bugs

  8. 38
    webseo67

    Hi! I tried to use your plugin but it shows me the last XX posts instead of the posts of the last XX days…
    mary kay skin care

  9. 37
    jibran

    Best-of-Programm jedoch probiert Josef Hader etwas, was viele Kollegen machen, er aber normalerweise nicht: Nummern spielen und dazwischen Lieder singen. best movie download sites

  10. Wow , I don’t know about this tips before.
    I do like Prevent author impersonation in WordPress comments as you post in tutorial.

  11. And if you download the right software, you can MP4 to DVD. How to remove DRM protection from M4V, WMV, M4P, AAC, M4A, WMA, OGG, iTunes, Napster, Rhapsody legally? So that you can burn iTunes to DVD or convert DRM files to other unprotected formats.

  12. Wow , I was looking for this tips until i found this
    It’s very nice tips.

  13. Thank. This ia a nice tip!

  14. it’s help a lot to me

  15. oww nice . thank you .)

Pages: « 6 5 4 [3] 2 1 » Show All

Leave a Comment

Before you comment: If you are having an issue with a script, please make sure you have read the entire article. Also, please read through the comments because most common issues have already been discussed many times. Thanks.


Be sure to wrap all code in <code></code> tags.