Opened 8 years ago
Last modified 18 months ago
#32056 new defect (bug)
wp_dropdown_roles() bug
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.1 |
Component: | Role/Capability | Keywords: | has-patch reporter-feedback |
Focuses: | administration | Cc: |
Description
Hello, in the function wp_dropdown_roles() located in wp-admin/includes/template.php there is a bug.
More specifically, around line 855 you can find
if ( $selected == $role ) // preselect specified role
In this condition you are comparing 2 strings, therefore the correct operator for comparison is "===". If compared only with "==" then the preselected role is wrong if the site has custom roles. Also the {} brackets are missing, but this is ok...
Please consider fixing it in the next version :)
Attachments (1)
Change History (12)
#2
@
8 years ago
I know the difference and it is rather significant one. In my case I have a custom role called "s39d". If the comparison is made with == then when a user has this role the role is not preselected on the dropdown, instead another role is in its place. If I change it to === then it works normally. Apart from that, it is a good practice to use === when comparing strings in php.
#3
@
8 years ago
That's an odd name for a roll, but you're point is much clearer now. Can you create a patch or do you need someone to do it?
#4
@
8 years ago
I am not familiar with creating patches for wordpress, I have just edited the file in my site. The only thing needed is one more "=" to be added in the if condition. I think it is a rather simple thing to do.
#5
@
8 years ago
I'll make the change and run the test and upload a patch shortly if everything goes well.
#8
@
8 years ago
- Keywords reporter-feedback added; dev-feedback removed
While the change makes sense, I can't see the actual bug here. What exactly does the string "s39d" match (using ==
) that it shouldn't?
#10
@
8 years ago
Hello,
These are the roles in my site:
http://prntscr.com/6x6d2z
If a user has the s39d role, in the edit user page instead of showing "39 days subscription" it was showing "Συνδρομή 12 μήνες" (the last role in the picture). When I changed it to "===" the correct role was showing.
PS: Someone created the roles that u see in Greek language and set the role names to 0,1 and 2. As you can see there is no checkbox to select and delete these roles, why is this happening and how can if fix that?
Thank you!
The only difference between
==
and===
is that the first one will type juggle and the second one is saying that they are equal, and of the same type. Could you please be more specific about the bug that you're experiencing?