Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1435859
Asking to recommend a product (plugin, theme, book, hosting provider), tool, library, or off-site resource is out of scope for this site, as it attracts opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 6 years ago.
Improve this questionI am creating a website that would need to only allow some specific email addresses to signup .
An example of this would allowing all emails ending in "@uniname.ac.uk
" but not allowing any "@gmail, @hotmail, etc...
".
Do you guys know of any WordPress email confirmation plugins or php code that would allow me to do that?
Finally, I don't really know how to code php so it would be super helpful if someone could help.
Thank you
Closed. This question is off-topic. It is not currently accepting answers.Asking to recommend a product (plugin, theme, book, hosting provider), tool, library, or off-site resource is out of scope for this site, as it attracts opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 6 years ago.
Improve this questionI am creating a website that would need to only allow some specific email addresses to signup .
An example of this would allowing all emails ending in "@uniname.ac.uk
" but not allowing any "@gmail, @hotmail, etc...
".
Do you guys know of any WordPress email confirmation plugins or php code that would allow me to do that?
Finally, I don't really know how to code php so it would be super helpful if someone could help.
Thank you
Share Improve this question edited Mar 19, 2019 at 21:33 Tanmay Patel 8111 gold badge7 silver badges11 bronze badges asked Mar 17, 2019 at 9:23 Afonso de SousaAfonso de Sousa 113 bronze badges2 Answers
Reset to default 1Just copy the above code and paste it into your theme’s functions.php file. Here I am going to show you the code which will reject registration from all others domain's email addresses and Only allowing @uniname.ac.uk email addresses to create an account. See the code below
function is_valid_email_domain($login, $email, $errors ){
$valid_email_domain = array("uniname.ac.uk");
$valid = false;
foreach( $valid_email_domain as $d ){
$d_length = strlen( $d );
$current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
if( $current_email_domain == strtolower($d) ){
$valid = true;
break;
}
}
if( $valid === false ){
$errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: you can only register using @uniname.ac.uk emails' ));
}
}
add_action('register_post', 'is_valid_email_domain',10,3 );
Requirements
In Settings->General, the box Anyone can register must be checked. Email address entered in Email field of registration form, must have an email domain equal to '@uniname.ac.uk'
Email address Validation
To validate email address, we can use 'registration_errors' filter hook.
Code
Insert the following code into functions.php of your active theme (child theme, if exists):
function wpse_check_email_domain($errors, $sanitized_user_login, $user_email) {
$start = strpos(strtolower($user_email), '@uniname.ac.uk');
if(!$start)
$errors->add('ERROR', 'Only users with "@uniname.ac.uk" email domain can register!');
return $errors;
}
add_filter('registration_errors', 'wpse_check_email_domain', 10, 3);
Use it as a must use plugin
The code above is not really theme related. Use it in functions.php, for testing only. After testing, remove it from functions.php, create a php script (eg. domain-check.php), put the code in it (do not forget <?php
as a first line), and save this script in 'wp-content/mu-plugins folder.
Explanation
After registration form submission, the hook 'registration_errors' will be triggered. The callback function 'wpse_check_email_domain' will be executed, and will return an error, if email domain is incorrect. The error message will appear on registration form. If there are no errors, registration process will continue.
本文标签: pluginsOnly allowing some emails to create an account
版权声明:本文标题:plugins - Only allowing some emails to create an account 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745673933a2669735.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论