#56683 closed defect (bug) (invalid)
User role can't be set
Reported by: | t3mmx | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | trivial | Version: | 6.0.2 |
Component: | Role/Capability | Keywords: | |
Focuses: | Cc: |
Description
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 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
Change History (5)
This ticket was mentioned in Slack in #core-test by ironprogrammer. View the logs.
2 years ago
#3
in reply to:
↑ 2
@
2 years ago
- Keywords needs-testing-info reporter-feedback removed
- Severity changed from normal to trivial
Replying to ironprogrammer:
Welcome to Trac, @t3mmx, and thank you for the report!
Would you please clarify if the
customer
andagent
roles already exist before the provided snippet is run? This will be helpful for other contributors as they work to reproduce this issue.
Another item to confirm: Did the provided code work in WordPress 5.9?
For guidelines on test reproduction instructions, please see the Bug Testing Instructions Template in the Test Handbook 🙌🏻
I found the source of the problem, and it was not a bug. Really SORRY. I discovered
that a conditional tag cannot be called from the 'init' hook to which I had attached the function.
The code was working before and I don't remember having made any changes to this file, which is why I immediately thought it was a bug. But after checking this was not the case. I haven't found a way to delete the ticket, I'm a little ashamed. Really sorry
Welcome to Trac, @t3mmx, and thank you for the report!
Would you please clarify if the
customer
andagent
roles already exist before the provided snippet is run? This will be helpful for other contributors as they work to reproduce this issue.Another item to confirm: Did the provided code work in WordPress 5.9?
For guidelines on test reproduction instructions, please see the Bug Testing Instructions Template in the Test Handbook 🙌🏻