
Originally Posted by
Rich Pedley
This may be a silly question, and I may end up not even using it, but...
I have a scenario (shopping cart) where I want to automate the user creation as much as possible. Now I know how to do this using a simple wp_create_user. But this calls username_exists to check to see if that name already exists, and rightly so. Now I realise that I may get the occasional error with a duplicate email address, that I can cope with. But what I'd like is for a way of changing the username if it already exists automagically behind the scenes, with no further user intervention.
eg. username Rich exists, so use Rich47 sort of thing.
What is the easiest way of doing this with minimal db calls?
Or should I forget it and add a field for them to fill in and keep amending until they find a free name? (which is what I'm trying to avoid).
Currently I'm thinking of creating an array of possible names, and then trying to construct a single query that checks for all of them and returns which one(s) are available for use. This check would be run prior to wp_create_user or via the pre_user_login filter.