Maybe look for the usernames-i18n-fix plugin. It allows much more that underscores, but reading it and the place it hooks to, you may be able to craft something to your liking.
Lonemadmax…
This seemed to do the trick. I looked at the plugin, and I can’t understand any of that crap. It’s only a few lines of code in the plugin, but it seemed to work. As long as there isn’t a reason why I SHOULDN’T just let it run as it was designed to do, then I’ll leave it the way it is.
Thanks for your suggestion!
At the end of the plugin you can see:
add_filter('user_sanitize', 'user_sanitize_i18n_fix', 10, 3);
That adds the function defined in the plugin to the user_sanitize
hook. Grepping the core files for user_sanitize
, you find return apply_filters( 'user_sanitize'
[…] in bb-includes/formatting-functions.php
, in the function user_sanitize
. When that function is called with strict = true, it removes what it considers not to be a letter, a number or a ‘-‘ from the first parameter (the provided username), and replaces repetitions of ‘-‘ with just one. So the underscore is removed. When strict is false, underscores are kept. Another effect is that accented characters and other such niceties of international scripts are also invalidated.
After doing that, it runs the filters, telling them its result, the original value and the value of strict. If installed, usernames-i18n-fix
will be one of those filters. It returns the original username value (that is, with whatever characters were there from the beginning) if not in strict mode. If strict is true, it just replaces repetitions of ‘-‘ with only one ‘-‘.
So that’s how I read it. But I don’t know if the names really need the sanitazion.