Skip to content

Instantly share code, notes, and snippets.

@adczk
Created December 1, 2023 10:36
Show Gist options
  • Save adczk/30736ec67478ee287d3a7ab11bd870eb to your computer and use it in GitHub Desktop.
Save adczk/30736ec67478ee287d3a7ab11bd870eb to your computer and use it in GitHub Desktop.
Block WordPress user account registration by e-mail domain
<?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