Ban certaine mails registration wordpress

You want to block certain email registrations in WordPress. There are a few ways to achieve this. Here are a few methods:

Method 1: Using a plugin

You can use a plugin like "Limit Login Attempts" or "WP Limit Registration" to block certain email registrations. These plugins allow you to specify a list of blocked email addresses or domains.

Method 2: Using a custom function

You can add a custom function to your WordPress theme's functions.php file to block certain email registrations. Here's an example:

function block_suspicious_email_registrations($user_email) {
    // List of blocked email addresses or domains
    $blocked_emails = array('[email protected]', '[email protected]', '[email protected]', '[email protected]');
    $blocked_domains = array('example.com', 'example.net');

    // Check if the email address is in the blocked list
    if (in_array($user_email, $blocked_emails) || strpos($user_email, '@')!== false && in_array(substr($user_email, strpos($user_email, '@') + 1), $blocked_domains)) {
        // Block the registration
        wp_die(__('Sorry, your email address is not allowed to register.', 'your-theme'));
    }
}
add_action('user_register', 'block_suspicious_email_registrations');

This function checks if the email address is in the blocked list or if the domain is in the blocked list. If it is, it blocks the registration and displays an error message.

Method 3: Using a filter

You can use a filter to modify the wp_insert_user function and block certain email registrations. Here's an example:

function block_suspicious_email_registrations($user_id) {
    // List of blocked email addresses or domains
    $blocked_emails = array('[email protected]', '[email protected]', '[email protected]', '[email protected]');
    $blocked_domains = array('example.com', 'example.net');

    // Check if the email address is in the blocked list
    $user_email = get_userdata($user_id)->user_email;
    if (in_array($user_email, $blocked_emails) || strpos($user_email, '@')!== false && in_array(substr($user_email, strpos($user_email, '@') + 1), $blocked_domains)) {
        // Block the registration
        wp_delete_user($user_id);
        wp_die(__('Sorry, your email address is not allowed to register.', 'your-theme'));
    }
}
add_filter('wp_insert_user', 'block_suspicious_email_registrations');

This function checks if the email address is in the blocked list or if the domain is in the blocked list. If it is, it deletes the user account and displays an error message.

Remember to replace the [email protected], [email protected], etc. with the actual email addresses or domains you want to block.