Tips : Domain mail problem solved!

Hi everyone,

I'm working on the new version of my theme and by the way on a big website which is a serious project for me.

I wanted to add a feature to Elgg => Approve users who have only a mail adress who belong to a specific domain

I saw members of the community looking for such a code so here is the thing :

No plugin needed so it's very light code

Edit the file engine/lib/users.php

go straight to the line 921

between those two lines :

$email = trim($email);
 
// A little sanity checking

Insert this block :

$allowed = array('example.com', 'example2.com');

// Make sure the address is valid
if (filter_var($email, FILTER_VALIDATE_EMAIL))
{
$domain = array_pop(explode('@', $email));

if ( ! in_array($domain, $allowed))
{
$email = 0;
}

}

Now, your website will only registration for users who have a email adress like john.smith@example.com or john.smith@example2.com

Hope you liked it!

  • In actions/register.php there the plugin hook 'register', 'user' triggered. It might be possible (better?) to use this plugin hook to check for the email domain. Then you could include the check in a separate plugin - even with the possibility to allow definition of allowed domains via site. You would not need to modify core files and would be safe to not lose your modifications after the next site update. When not including the option to define the email domain list on site the code of such a plugin wouldn't be more than a few lines either.

  • I make the fastest Elgg website I can : So instead of adding a plugin, which means a new start.php to execute and many files to load for just 1 feature, I prefer to modify the core directly

    Result : my website is as fast as facebook

    that's my philosophy ;-)

    The website is nearly finished

  • I wouldn't recommend modifying core files. Listen to iionly, it will save you problems

  • If you want to create a website that's difficult to administrate and complicated to upgrade, please do.

    But please don't post a general advice to modify core files when there's a simple way to achieve the same by coding it as a plugin. Many files? It's just start.php and manifest.xml. And it won't slow down your site either. Site speed mostly depends on a well configured server (and some minimum needed hardware requirements). Implementing features as plugins or not won't influence your site speed noticeable. Of course, when the code is bad or adds some heavy-weight features it will slow down your site - but it will do so regardless if you have modified the core files or included it in the standard way as a plugin.

  • Ok ok I surrender! Don't shoot!