create random ID for Users
-
hello, is this plugin support create random ID for Users?
i want to use it as STUDENT ID
-
You can try this code snippet:
https://docs.ultimatemember.com/article/1683-how-to-generate-a-unique-account-id
@missveronicatv Hi, i’ve used the snippet in my site, but the ID doesn’t generate, it’s blank. The code is still valid?
How did you install the code snippet?
@missveronicatv First the snippet in the functions.php of my theme, then a text box in the profile form. Just as the tutorial said.
I tested the code snippet and it generated a custom ID when a new user registered.
Existing old users have a blank custom ID not being displayed at the Profile page.Okey, that was it. Is there any form to generate an ID for old users?
You can try this code snippet.
Install into your active theme’s functions.php file.If you have made any changes to the first code snippet you must do the same changes in this code snippet for this line like the
C-or the number 5:$unique_account_id = 'C-' . str_pad( $user->ID, 5, '0', STR_PAD_LEFT );After installing this code snippet display one profile page at your site and your new custom ID’s will be generated for your old users.
When the page displays after a while remove the code snippet from functions.php file.
add_action( "init", "um_update_unique_account_id" ); function um_update_unique_account_id() { $users = get_users(); foreach ( $users as $user ) { um_fetch_user( $user->ID ); $unique_account_id = um_user( 'um_unique_account_id' ); if( empty( $unique_account_id )) { $unique_account_id = 'C-' . str_pad( $user->ID, 5, '0', STR_PAD_LEFT ); update_user_meta( $user->ID, "um_unique_account_id", $unique_account_id ); } UM()->user()->remove_cache( $user->ID ); } }Thanks, but doesn’t work either.
I installed the new snippet right below the first, is correct?
The second snippet will execute when you display an UM page like a Profile page.
During creation of the page content all old users will be updated with their ID.@missveronicatv Sorry, but I don’t understand, after the snippet, what I have to do?
Have you got ID for old users now?
@missveronicatv No, still the same.
1. Install the second code snippet in your active theme’s
functions.phpfile.2. With your browser display a user profile page.
3. When UM is preparing to display this profile page the second code snippet is also being executed by WordPress.
4. Second code snippet will read all your old users and assign the unique custom ID to them and updating the database.
5. When you get the profile page to your browser display the second code snippet is ready with updating old users.
6. Remove second code snippet, it’s not needed any more.
7. Look at an old user profile where you have included the
um_unique_account_idmeta-key value in the profile page.This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.
Please feel free to re-open this thread if any other questions come up and we’d be happy to help. 🙂
Regards
I Added the code below in functions.php
add_action(“user_register”,”um_012022_generate_unique_account_id”);function um_012022_generate_unique_account_id( $user_id ) {$unique_account_id = ‘B-‘ . str_pad( $user_id, B, ‘0’, STR_PAD_LEFT );update_user_meta( $user_id, “um_unique_account_id”, $unique_account_id );}
with chnage the C letter to B and 5 number to 3
but the old users not update to new change so how can I Update the old Users to the new change ?
-
This reply was modified 3 years, 1 month ago by
abdullahalsalim.
-
This reply was modified 3 years, 1 month ago by
The topic ‘create random ID for Users’ is closed to new replies.