I wrote a plugin to enable hebrew characters in usernames. This is the full code:

add_filter ('sanitize_user', 'hu_sanitize_user', 10, 3);

//Overrides the Wordpress sanitize_user filter to allow hebrew letters and english letters only

function hu_sanitize_user ($username, $raw_username, $strict)
//Strip HTML Tags
$username = wp_strip_all_tags ($raw_username);

//Remove Accents
$username = remove_accents ($username);

//Kill octets
$username = preg_replace ('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);

//Kill entities
$username = preg_replace ('/&.+?;/', '', $username);

if ($strict){
    $username = preg_replace( '[\p{Hebrew}a-zA-Z]', '', $username );

//Remove Whitespaces
$username = trim ($username);

// Consolidate contiguous Whitespaces
$username = preg_replace ('|\s+|', ' ', $username);

return $username;


It works well, but the problem is that if the length of the username is more than 8 characters, it doesn't create a user in the users list. However, it does still send a confirmation email that the user was created - with the name and e-mail address missing from the message.

Any ideas what I'm doing wrong?

  • 1
    are you sure the user is not created? have you checked the DB table and the user's admin screen? Commented May 22, 2016 at 10:08
  • thanks mark, but i checked even the DB and user not created.
    – DrMosko
    Commented May 23, 2016 at 4:53
  • from looking at the code it seems that if a mail was sent then the user was created. There is probably something additional here.that is not made explicit in the question. Commented May 23, 2016 at 5:38
  • tx again, I know that the code is good, but some how all the wordpress users that download this have the same problem, and I can't figure it out.
    – DrMosko
    Commented May 24, 2016 at 12:56
  • 1
    So you're using strict mode? Where did you turn on strict mode?
    – Minh Tri
    Commented May 27, 2016 at 13:21

1 Answer 1


This is not a complete answer, but it's an attempt at giving you some direction. Hopefully with the community here we can come up with a solution for you!

Firstly, I've been able to replicate your issue:

  1. I took your code and placed it in my theme's functions.php for now.
  2. I removed the if( $strict ) test
  3. I tried registering an 8 character Hebrew name - it worked
  4. I removed your function and tried again - it failed (this confirms your function works)
  5. I added your function and tried with a 9 character Hebrew name - it failed

(for non-Hebrew speakers following along, I just used Google Translate and translated my own name to Hebrew, then dropped characters).

When it didn't work, the error I got was:

ERROR: Couldn’t register you… please contact the webmaster !

I've never seen this error before. It comes from wp-includes/user.php. What this tell us, hunting through the order of this, is that wp_create_user(), and therefore wp_insert_user(), is either returning false or an error object.

wp_insert_user() has a heck of a lot of filters we could potentially plug into to help this work. It may be tripping up one of these.

Alternatively, it may be a database issue. This StackOverflow answer has some ideas for supporting Hebrew characters in a MySQL database. My table encoding was already set to utf8_general_ci but my database itself wasn't, so I changed that and unfortunately it didn't resolve it. I also tried running the SET NAMES query through wpdb, but it's possible it's not meant to work like that.

Where to from here

I'm hardly a database expert, so I'm not sure if this is a database limitation that we may end up not being able to get around. For now, I think the best chance lies in one of those filters that wp_insert_user() goes through.

I don't have time right now to hunt through these in depth and work out where it's tripping up, but hopefully this gives you a decent head start - if I can I'll come back and see what else I can find.

  • thanks for ur trouble, I did not get any error at all, also tried to convert string to utf 8, did DB check, but this is not the problem, Im hopeless....
    – DrMosko
    Commented Jul 1, 2016 at 6:39
  • @DrMosko What about the other filters that wp_insert_user() calls?
    – Tim Malone
    Commented Jul 4, 2016 at 23:32
  • that wont fix the bug, but i get u for changing the approach,
    – DrMosko
    Commented Jul 6, 2016 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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