Results 1 to 5 of 5

Thread: wp_create_user & username_exists

  1. #1
    Rich Pedley's Avatar
    Rich Pedley is offline Hello World
    Join Date
    May 2009
    Location
    Liverpool, UK
    Posts
    92

    Icon5 wp_create_user & username_exists

    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.

  2. #2
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Quote Originally Posted by Rich Pedley View Post
    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.
    Why not do it via javascript, and query the database when the appropriate form field (e.g. "Username") loses focus? Then, display feedback next to the form field, based on the query response (e.g. "Username Avaliable" or "Username Not Avaliable. Please try another.").
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  3. #3
    Rich Pedley's Avatar
    Rich Pedley is offline Hello World
    Join Date
    May 2009
    Location
    Liverpool, UK
    Posts
    92

    Default

    Because I hate javascript?

    Actually having posted I asked my significant other and she simply said why not just get the next user id and append that... That should ensure they are all unique.

    moral: ask the wife before posting.

  4. #4
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Quote Originally Posted by Rich Pedley View Post
    Because I hate javascript?
    Actually, in-line form data-entry validation is good for user experience - but, personal preference/to each his own, and all that.

    Actually having posted I asked my significant other and she simply said why not just get the next user id and append that... That should ensure they are all unique.

    moral: ask the wife before posting.
    Always a wise moral!
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  5. #5
    Rich Pedley's Avatar
    Rich Pedley is offline Hello World
    Join Date
    May 2009
    Location
    Liverpool, UK
    Posts
    92

    Default

    Quote Originally Posted by chipbennett View Post
    Actually, in-line form data-entry validation is good for user experience - but, personal preference/to each his own, and all that.
    I haven't done testing to see how accessible it is though. If implemented correctly I'm sure it can be though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •