I have a client who wanted to assign member IDs to their users after they had registered.
They wanted the member IDs to be random and were preprinted so that the user could get some things by snail mail with this new member ID attached so using the WordPress User ID wasn’t an option.
The ID had to be something that would be hard to guess so that someone couldn’t just keep guessing IDs at the computer to find information about a user.
When the user registered I set up a member_number
field with 'xxxxxxx'
in the usermeta
database table so that it would be easy to find new users who had not been assigned yet.
When the administrator was ready to ship out their materials, they could scan (via QR code) or manually enter the member ID on the materials that were to be shipped. I wanted my code to pull up all unassigned users so they could decide which user to assign the code.
Finding the unassigned users could be done like I did it in this post.
Once the user id is found in the database, my new page can be accessed using Get variables like this: http://example.com/assign?user=1234&id=wixopdy
where 1234
is the user’s ID and wixopdy
is a random member ID that’s gotten from their materials.
Now my code can access that information using those GET variables. The update_user_meta
function will update the member_number
in the database with the new member ID.
// if (!($id = $_GET['id'])) { echo 'No Member Number'; } else if (!($user_id = $_GET['user'])) { echo 'No User ID'; } update_user_meta($user_id, 'member_number', $id,'xxxxxxx'); echo '<div id="success-message">Number '.$id.' has been assigned to '.get_user_meta($user_id,'first_name',true).' '.get_user_meta($user_id,'last_name',true).'</div>'; //
I use the PHP code for posts plugin to add the code directly into my WordPress page instead of making a new page template in the theme.
This is a lot less work for me and I feel it’s a bit more efficient. I could be wrong about that, but it’s been working well for me and much easier to maintain since I can put small chunks of code in my pages.
I just surround my code by [php]
and [/php]
instead of <?php
and ?>
.