Home › Forums › ACF PRO › Generate random code › Reply To: Generate random code
I suggest you look at do_action( ‘user_register’, int $user_id, array $userdata )
Which fires immediately after a new user is registered.
So as an example (code untested), you could look at something like:
<?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, 'your_acf_field_name', $randomise );
}
You need to setup the ACF field and link it to the user role(s). You then need to update the above example with the field name.
Add the code to your function file and test it.
If it doesn’t work, look to try and debug why.
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.