Home > Blockchain >  Insert Prefix in to wordpress username when save on user_new_form
Insert Prefix in to wordpress username when save on user_new_form

Time:04-04

I'm struggling with the appropriate way to insert a prefix "unit_" in to the username when a new user is created. I'm assuming it can be achieved with a wordpress function that hooks in to the appropriate function that fires post user_new_form submit.

Basically I'm trying to skirt around the validation error that requires a username be letters and numbers for an implementation where usernames are numbers only by adding a prefix before that validation fires.

Any help on best approach would be greatly appreciated!

CodePudding user response:

There are a number of filters you can use, as documented here https://developer.wordpress.org/reference/functions/wp_insert_user/#source

i.e pre_user_login illegal_user_logins

you can go through the function to get all the filters applied

CodePudding user response:

turned out to actually be a little more complicated than that. I had to filter the validations in the wpmu_validate_user_signup function and then I used wp_pre_insert_user_data filter to modify the username.

  • Related