Force Valid Email Addresses
In WordPress, you can enable an option that requires commenters to supply a name and an email address, but oddly enough, it doesn't validate the email address submitted. This is simple enough to add, as WordPress already has a function for validating email addresses, and because it can be done via a REALLY simple plugin.
Just save this plugin in your (enabled) my-hacks.php file or as its own file (your choice… it all depends on how cluttered your plugin screen is getting).
<?php
/*
Plugin Name: Force Valid Email in Comments
Version: 1.0
Plugin URI:
Description: This simple function is run when comments are being submitted, and uses a built-in WordPress function to ensure that commenters' e-mail addresses are at lead validly formed. It only does this check if you have WordPress set to require name and e-mail.
Author: Mark Jaquith
Author URI: http://www.txfx.net/
*/
function force_valid_comment_email($comment){
global $email;
if ( get_settings('require_name_email') && !is_email($email))
die( __('The email address you entered was invalid.') );
return $comment;
}
add_action('post_comment_text', 'force_valid_comment_email', 1);
?>
One thing to note: it only performs the check if you have WordPress set to require name and email. If you don't require an email address, what do you care if it is validated? Then again, if you do want it to check regardless, just change the conditional statement to this:
July 7th, 2004 at 8:01 pm
Rather than ping ScriptyGoddess multiple times and clog my sideblog with even more WordPress links, I decided to plop 'em all here. I'm going to give WordPress a try again on my course website, since there are various hacks that…
July 8th, 2004 at 1:41 pm
July 8th, 2004 at 8:47 pm
Hi there, I'm just a random passer by, but I had a couple questions, but not to be a pest.
First off, I like this hack, however, i dont have a my-hacks.php anywhere and have been unable to figure out where that file should go and what else it should contain.
Also, 2 features of your blog that I really like and was wondering if you could point me to the right place to add them to my blog.
One would be the "Read more…" and "Read more here…" Thats a really nice feature, is there a site explaining how to install that? or is it a custom hack?
Second, I really like the buttons above this comment box, taking away those yuckie looking tags that are normally up there, and putting those buttons would be really nice on my blog. Is there a page for that hack? or again is it custom?
Thanks for your time.
Josh.
July 8th, 2004 at 8:56 pm
Josh - Updated the post to point to the wiki page about the my-hacks.php page - it's here:
Read more.. thing is the show/hide plugin here.
The buttons are here.
Just about everything you see on this blog is published or bookmarked on the site. So just use the search form at the top and you should be able to find it.
July 8th, 2004 at 9:05 pm
Very cool, thanks for the quick reply. Looks like there is another cool hack i like, that img that identifies you as the blog author and me as subscribed on this comments page.
Thanks for the help.
July 8th, 2004 at 9:19 pm
August 28th, 2004 at 11:13 pm
scriptygoddess: force valid email addresses for WP commenters [...]September 28th, 2004 at 11:54 pm
how about a plugin that checks if an e-mail is active as in it's not anything@anyaddress.com that's just made up by the poster?
October 29th, 2004 at 2:36 pm
Sigh. Having to set all this stuff up again due to server problems and for the life of me I can't get this to work, as witnessed by the 9 or so bogus comments I made on my latest post! LOL. Any suggestions? (www.rigdonia.com/wp)
October 29th, 2004 at 2:37 pm
erm. Nevermind.
February 15th, 2005 at 5:45 pm
This has decided not to work when a user is logged in and tries to make a comment. Is there any way to get this to work when calling from a users profile?
February 15th, 2005 at 6:03 pm
Is there any way to make an exclusion to this rule if a user is logged in?
April 1st, 2008 at 4:57 am
[...] hack uses an existing function built into WP to validate eMail addresses of those placing comments to [...]