I have a client who wants to register users and give them a unique ID number when they complete registration. (Kind of a member number sort of thing)
Can I just setup the WP member table to start id numbers in the high 10 digit range?
User experience would be:
- user would visit the site
- user would register
- WP would issue an 10 digit id number
The
ID
column of theusers
table isAUTO_INCREMENT
, so you can set the base counter to a high number:All new users will have an
ID
that is higher than this value. Calling this operation is safe, if you accidentally set it to a low number either nothing happens (in aInnoDB
table), or it is set to the highest existing number + 1 (in aMyISAM
table).The ID field will definitely work. If you wanted a larger number you could just add 10,000 to it and it will still be unique.
Other ways of doing this get more involved. You can store a value in the wp_options table, and then fetch, increment, save, but you have a small window of opportunity where two people could end up with the same number, so you need to check for that and repeat if there was a collision. You can generate MD5 (or SHA1) hashes from some chosen bits of user info, but this will give you a big, nasty string of characters. This can be useful when generating a UUID (Universally Unique ID) across multiple systems because the chance of collision is vanishingly small.
I guess also easy would be to hook into the registration process (pre data get’s submitted to DB) and just change the
user_registered
column fromwp_usermeta
table with some preg_replace for empty spaces. They would be unique as long as you’re not submitting them in the exact same second. The value won’t ever be changed by anyhting after the registration process + it would allow ordering by registration time if you may need that.