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 );
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.