WordPress plugin to white list user registrations
This was a request from a school for a plugin that would only allow users that had email at the school domain ( user@school.edu ) to register as users on the blog.
Anyone trying to register with an email address not from that domain gets redirected to an error page.
To make this work:
1) Open the plugin in a text editor and change @good.edu on line 20 to be the domain you wish to allow users.
2) Upload the plugin to your plugin directory and activate.
Now you can easily change the error page for users not from your domain. It is on lines 31->36
This is just standard html with print in front of each line and the line in quotes.
print “<html>\n”;
print “<head><title>Restricted email address</title></head>\n”;
print “<body>\n”;
print “<h2> Sorry users are restricted to our school </h2>\n”;
print “</body>\n”;
print “</html>\n”;
Registration White List WordPress plugin
If you wish to white list several domains change the plugin code like I did below. This allows three domains to register
$new_user = $_POST['user_email'];
$good_email1 = “@good.edu”;
$good_email2 = “@good2.com”;
$good_email3 = “@good3.org”;
// pull domain out of user email address
$new_user_domain = explode( ‘@’, $new_user);
$new_user_domain = ‘@’ . $new_user_domain[1];
//for multiple domains add more $good_emailx above
// and add more lines below same as $good_email2 line but with $good_emailx
// no || ( or symbol ) on last email domain you are checking.
if (( strcasecmp ( $new_user_domain, $good_email1 ) == 0 )||
( strcasecmp ( $new_user_domain, $good_email2 ) == 0 )||
( strcasecmp ( $new_user_domain, $good_email3 ) == 0 )
){
Add A Comment
You must be logged in to post a comment.