Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#32056 new defect (bug)

wp_dropdown_roles() bug

Reported by: InS0mN1aC Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 2.1
Component: Role/Capability Keywords: has-patch reporter-feedback
Focuses: administration Cc:


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)

32056.diff (695 bytes) - added by valendesigns 3 years ago.

Download all attachments as: .zip

Change History (11)

#1 @valendesigns
3 years ago

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?

#2 @InS0mN1aC
3 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 @valendesigns
3 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 @InS0mN1aC
3 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 @valendesigns
3 years ago

I'll make the change and run the test and upload a patch shortly if everything goes well.

#6 @InS0mN1aC
3 years ago

Cool! Thanks for your time :)

3 years ago

#7 @valendesigns
3 years ago

  • Keywords has-patch dev-feedback added

Patch uploaded. Thanks for the bug report.

#8 @johnbillion
3 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?

#9 @johnbillion
3 years ago

  • Version changed from 4.1.2 to 2.1

#10 @InS0mN1aC
3 years ago

These are the roles in my site:

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!

Note: See TracTickets for help on using tickets.