[wp-trac] [WordPress Trac] #56683: User role can't be set

WordPress Trac noreply at wordpress.org
Thu Sep 29 03:15:33 UTC 2022


#56683: User role can't be set
-----------------------------+-----------------------------
 Reporter:  t3mmx            |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  Role/Capability  |    Version:  6.0.2
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 It seems that the new WordPress version (6.0.2) overrides the role
 variable in the wp_insert_user function. I made a plugin and Before, it
 worked properly, but now the value defined by default in the wordpress
 dashboard takes precedence over the wp_insert_user function.
 Here is the code that worked properly before. Depending on the page where
 the user was at the time of registration, his role is defined.

 {{{#!php
 <?php

 if (is_page('register')) {
     $user_role = 'customer';
 } 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);
 }}}

 But unfortunately there is only the default predefined role in the
 wordpress dashboard that is assigned. I need the role assigned to the
 registration.
 But despite this, I tried to modify the role of the user just after
 registration with wp_insert_user, and the action hooks user_register,
 add_user_role and set_user_role; None of them works

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56683>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list