The effects of alcohol on sustanon 250 leucine for – real weight loss & bodybuilding benefits?
Share:
Notifications
Clear all

Question prevent name reuse

4 Posts
2 Users
0 Reactions
145 Views
Posts: 2
Topic starter
(@chuck)
New Member
Joined: 2 weeks ago

Everyone commenting on our website is a guest, without a login and password.

Once a comment has been made by a "name" and an "email address", we would like to require all future comments that use that "name" to have to use that "email address", or give an error message something like "name already in use by someone else, please choose a different name".  

The idea being that we do not want different people using the same "name".

Is this already possible with a combination of plugins and or addons?

How can this be done?

 

3 Replies
Asti
Posts: 7658
 Asti
Support
(@asti)
Illustrious Member
Joined: 7 years ago

Hi,

You can use the preprocess_comment hook to make the customization you want. 

More info here:  https://developer.wordpress.org/reference/hooks/preprocess_comment/

Reply
Posts: 2
Topic starter
(@chuck)
New Member
Joined: 2 weeks ago

How do I find all of the previously used 'comment_author' + 'comment_author_email' pairs to verify that the current 'comment_author' has not previously been associated with a different  'comment_author_email' ?

Reply
1 Reply
Asti
 Asti
Support
(@asti)
Joined: 7 years ago

Illustrious Member
Posts: 7658

@chuck 

Here is the code provided by our developers: 

add_filter('preprocess_comment', function ($commentdata) {
    global $wpdb;
    $sql = "SELECT `comment_author_email` FROM `{$wpdb->comments}` WHERE `comment_author` = %s LIMIT 1";
    $author_email = $wpdb->get_var($wpdb->prepare($sql, $commentdata['comment_author']));
    if (!empty($author_email) && $commentdata['comment_author_email'] !== $author_email) {
        wp_die('name already in use by someone else, please choose a different name.');
    }
    return $commentdata;
});

Insert the code into your WordPress active theme's function.php file. 

Reply
Share: