I’m working on a WordPress application and we have added a custom field via the advanced custom fields plugin.
This is working well!
We need to set a specific role though based on the Registration Pin that we have added via the advanced custom fields plugin.
We tried to update the code in users.php, within the function wp_insert_user( $userdata ) {
method, but we have failed.
Here is the code we tried to set:
debug_to_console('hey cindyyyyyyyyyyyyyy');
debug_to_console($userdata);
if ( isset( $userdata['role'] ) ) {
$user->set_role( $userdata['role'] );
} elseif ( ! $update ) {
if ($userdata['registration_pin'] == 9742)
{
$user->set_role('club_member');
}
else if ($userdata['registration_pin'] == 9744) {
$user->set_role('new_member');
}
else{
$user->set_role( get_option( 'default_role' ) );
}
//$user->set_role( get_option( 'default_role' ) );
// $user->set_role('new_member');
// $user->set_role('club_member');
}
In this code, it passes the 2 if statements and goes directly to the else which sets the ‘default role’.
2
Answers
Here is a valid answer:
Full code on function:
The only way it would pass those two "if statements" would be because either $userdata[‘registration_pin’] is not equal to 9742 or 9744, or $userdata[‘registration_pin’] doesn’t exist in the $userdata
I am sure the problem is $userdata[‘registration_pin’] doesn’t exist, ACF wouldn’t save a custom field in your userdata like that… by default custom fields from ACF are saved in the user_meta table
You should be able to access the registration key with this: