Dear all,
I trying to affect a user card member using the biggest value found on the user_meta table sor subscribers. Everythinks is working well, but i have an issue.
Im changing the value of an hidden field (user_uuid) with a hook, and affect him a value.
Problem is, two person can be connected at the same time, using the same form, and has the same populated value at the same time.
Solution should be to affect the value, only when the form is sent.
Any idea how to make it ?
My code bellow.
add_filter('gform_field_value_maxnummembre', 'populate_memberid');
function populate_memberid($value){
$args = array(
'role' => 'Subscriber',
);
// The Query
$user_query = new WP_User_Query( $args );
// User Loop
if ( !empty( $user_query->results ) ) {
foreach ( $user_query->results as $user ) :
$uuid = get_user_meta( $user->ID, 'user_uuid', true);
echo '<p>' . $user->display_name . ', Membre n° '.$uuid.'</p>';
$nummembre[] = $uuid;
endforeach;
$maxnummembre = (max($nummembre) + 1);
echo 'Nouveau : '.$maxnummembre;
return $maxnummembre;
}
}