I do not know, however it appears that evidently the brand new WordPress model (6.0.2) overrides the position variable within the wp_insert_user
operate. Earlier than it labored correctly, however now the worth outlined by default within the wordpress dashboard takes priority over the wp_insert_user
operate.
Right here is the code that labored correctly earlier than. Relying on the web page the place the consumer was on the time of registration, his position is outlined.
if (is_page('register')) {
$user_role="buyer";
} elseif (is_page('become-agent')) {
$user_role="agent";
}
$user_infos = [
'user_login' => $user_login,
'user_pass' => $user_pass,
'user_email' => $user_email,
'user_registered' => date('Y-m-d H:i:s'),
'role' => $user_role
];
$new_user_id = wp_insert_user($user_infos);
However sadly there’s solely the default predefined position within the wordpress dashboard that’s assigned. I would like the position assigned to the registration.
However regardless of this, I attempted to switch the position of the consumer simply after registration with wp_insert_user, and the motion hooks user_register
, add_user_role
and set_user_role
; None of them works