1

It's since 1 month ago, every day we'll receive some tens of new user registration with username containing like YggrnCyhorgeVH or AurizarCyhorgeVH, etc..

Ip and user agent are different every time, so I thinked to avoid user registration with this name.

Is there a hook/action/filter where to intercept the user registration and deny it?

PLEASE do not suggests plugin/captcha or others. I made a specific question.

  • Have you tried a captcha? This would filter out most automated bots – xvilo Mar 3 '17 at 7:24
1

Following code should work for you, but I can not guarantee that because your form is so heavily (and badly) customized. I have tested it on not customized registration form and it worked just fine.

function cyhorge_check_fields( $errors, $sanitized_user_login, $user_email ) {

    if ( preg_match('/(CyhorgeVH)/', $sanitized_user_login ) ) {
        $errors->add( 'username_error', __( '<strong>ERROR</strong>: User contains CyhorgeVH string.', 'my_textdomain' ) );
    }

    return $errors;
}

add_filter( 'registration_errors', 'cyhorge_check_fields', 10, 3 );

SOURCE

EDIT: Another possible solution:

function prevent_cyhorge_user( $user_login, $user_email, $errors ) {

    if ( strpos( $user_login, 'CyhorgeVH' ) ) {
        $errors->add( 'username_error', __( '<strong>ERROR</strong>: User contains CyhorgeVH string.', 'my_textdomain' ) );
    }

}

add_action( 'register_post', 'prevent_cyhorge_user', 10, 3 );

Notice that the second function is using strpos instead of preg_match which probably a bit faster, but preg_match provides more flexibility if needed.

Both should work from either theme's functions.php or as a plugin.

  • Thanks, I was exactly looking for an hook like "registration_errors" ! – realtebo Mar 6 '17 at 11:17
0

Get spam filters for your site - captcha, Wordfence etc. General security helps against stuff like this.

  • I cannot, my login form is customized, heavily customized, very BAD customized (I'm not guilty). I asked how to intercept registration event and interrupt it if I want. – realtebo Mar 3 '17 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.