Registration only for specific domains (like for instance @company.com)

How can i grand users with a certain (company) e-mail address to register and how do i monitor this? Is there a code snippet to do this?
Thanx.

Please check this topic No-Bot Registration | HivePress Support

Hi, may be you can help me. With the use of the script on Allow registration for certain email domain on WordPress - CodeSpeedy i can filter new registrars for the site and get the green light (see screenshot were a registration is stopped), but only through the WordPress registration form. When I try it through the use of the registration form of rentalhives form, nothing happens and a new user with an e-mail domain that is not allowed can register?!?
RentalHives is using the same login and registration form as WordPress, i read in the documentation. But why is this not working?

Yes, we use the same functions and the default WP registration form but I guess the plugin you’re using is applied to APIs specific to the default form, so it doesn’t work for the front-end one.

If there are only a few allowed domains, you can try using this code snippet instead of a plugin. The current code snippet accepts only Gmail and Yahoo email domains on the registration form but you can change them by your requirements:

add_filter(
	'hivepress/v1/forms/user_register/errors',
	function( $errors, $form ) {
		$email = $form->get_value( 'email' );

		if ( $email && ! in_array(
			hivepress()->helper->get_last_array_value( explode( '@', $email ) ),
			[
				'gmail.com',
				'yahoo.com',
			],
			true
		) ) {
			$errors[] = 'error text here';
		}
		
		return $errors;
	},
	1000,
	2
);
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Hello,

I need to implement a spam filter on the registration form to prevent “invalid” domain name, incomplate email and blocked user. How can i do it?

I tried to do some quick snippets but wasn working.

add_filter( 'hp_user_register_args', 'block_user_by_email_or_domain', 10, 1 );
function block_user_by_email_or_domain( $args ) {

    // Email esatte da bloccare
    $blocked_emails = array(
        'utente@example.com',
        'spamuser@gmail.com'
    );

    // Domini email da bloccare
    $blocked_domains = array(
        'mailinator.com',
        'tempmail.com',
        '10minutemail.com',
        'dispostable.com'
    );

    $email = isset($args['user_email']) ? strtolower(trim($args['user_email'])) : '';

    // Controlla email specifiche
    if ( in_array( $email, $blocked_emails ) ) {
        throw new \Exception( 'Registrazione non consentita con questa email.' );
    }

    // Estrai e controlla il dominio
    if ( strpos($email, '@') !== false ) {
        $domain = substr(strrchr($email, "@"), 1);
        if ( in_array( $domain, $blocked_domains ) ) {
            throw new \Exception( 'Registrazione non consentita da questo dominio email.' );
        }
    }

    return $args;
}

Hi,

Please clarify, do you want to allow registration only for specific email domains?

Hi @andrii I want to block specific domain and also specific email address. Like if a user create alisting for spam only I want to ban him by his email.

I guess your best option is to moderate vendor registration / listings submission under hivepress > settings.

image

Hi,

Please check the solution in this topic.

​I hope this is helpful to you