Home › Forums › ACF PRO › Generate random code › Reply To: Generate random code
Just tested and works fine
Here’s what I did:
1) Create an ACF text field called Random String
2) This creates the label random_string
3) For testing, I assigned this field to User Role is equal to All
4) I added the below code to my functions.php file:
<?php
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
####generate the random number
#get current date/time
$date = date('YmdH:i:s');
#randmoise
$randomise = ($date * 25);
update_user_meta($user_id, 'random_string', $randomise ); #change random_string to your ACF field label!!!
}
5) I registered a new user
6) I then clicked to edit the user, scrolled down to my new Random String field, this was the result: 50527810375
Code and entire process tried and tested!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.