Created
December 1, 2023 10:36
-
-
Save adczk/30736ec67478ee287d3a7ab11bd870eb to your computer and use it in GitHub Desktop.
Block WordPress user account registration by e-mail domain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Block WordPress user account registration by e-mail domain | |
* Plugin URI: https://gist.github.com/adczk | |
* Description: Block WordPress user account registration by e-mail domain | |
* Author: adczk | |
* | |
* Author URI: https://gist.github.com/adczk | |
* License: GPLv2 or later | |
* | |
* Use as MU plugin; config in code comments | |
* | |
*/ | |
function wpmu_stop_registration_by_domain( $errors, $sanitized_user_login, $user_email ) { | |
// below you list email domains to be blocked | |
// comma-separated | |
$blocked_domains = array( | |
'emaildomain.com', | |
'otherdomain.net', | |
); | |
// custom error message | |
$error_msg = "You're not allowed to register!"; | |
foreach ( $blocked_domains as $key=>$value ) { | |
if ( strpos( $user_email, $value ) !== false ) { | |
$errors->add( 'banned_domain_error', $error_msg ); | |
} | |
} | |
return $errors; | |
} | |
add_filter( 'registration_errors', 'wpmu_stop_registration_by_domain', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment