WordPress.org

Make WordPress Core

Opened 7 months ago

Closed 7 months ago

#40162 closed enhancement (fixed)

Don't alter the order of roles in the Role dropdown when editing a user

Reported by: johnbillion Owned by: johnbillion
Milestone: 4.8 Priority: normal
Severity: normal Version:
Component: Users Keywords: has-screenshots has-patch commit
Focuses: administration Cc:

Description

When editing a user, the user's current role gets moved to the top of the list of roles shown in the Role dropdown. Reordering items in a list can be confusing, and although the roles in WordPress aren't strictly hierarchical there is an implied hierarchy that should be maintained in this list.

Attachments (5)

editor.png (30.8 KB) - added by johnbillion 7 months ago.
contributor.png (30.4 KB) - added by johnbillion 7 months ago.
40162.diff (1.1 KB) - added by bor0 7 months ago.
customer.png (17.1 KB) - added by bor0 7 months ago.
User Role Dropdown.png (19.0 KB) - added by lukecavanagh 7 months ago.
User Role Dropdown after patch

Download all attachments as: .zip

Change History (16)

@johnbillion
7 months ago

#1 @johnbillion
7 months ago

  • Keywords has-screenshots added
  • Type changed from defect (bug) to enhancement

#2 @johnbillion
7 months ago

  • Keywords good-first-bug added

#3 @ketuchetan
7 months ago

Hi @johnbillion

So, you mean we need to display the all the roles list default way, not the user's current role gets moved to the top of the list?

If I understand properly then please let me know so I can add my patch here.

#4 @swissspidy
7 months ago

@ketuchetan That's how I understand it, yes.

#5 @lukecavanagh
7 months ago

Seems like that is defined here.
https://github.com/WordPress/WordPress/blob/master/wp-admin/user-edit.php#L363

Using this function.
https://developer.wordpress.org/reference/functions/wp_dropdown_roles/

So default user roles in core hierarchy would be the following then?

https://codex.wordpress.org/Roles_and_Capabilities#Summary_of_Roles

Super Admin
Administrator
Editor
Author
Contributor
Subscriber

How would additional user roles either custom added or by a plugin relate to the hierarchy of the user roles in core, would those be based on user capabilities, for example WooCommerce adds in two new user roles, Customer and Shop Manager.

https://codex.wordpress.org/Roles_and_Capabilities#Capabilities

Last edited 7 months ago by lukecavanagh (previous) (diff)

@bor0
7 months ago

@bor0
7 months ago

#6 @bor0
7 months ago

  • Keywords has-patch added; needs-patch removed

How would additional user roles either custom added or by a plugin relate to the hierarchy of the user roles in core, would those be based on user capabilities, for example WooCommerce adds in two new user roles, Customer and Shop Manager.

While related, I think this is out of scope for this ticket as this is only about not resetting the index of the currently selected role.

After proposed patch (40162.diff) here's how it appears like:

@lukecavanagh
7 months ago

User Role Dropdown after patch

#7 @lukecavanagh
7 months ago

  • Version set to 4.7.3

@bor0

The patch applies cleanly and works well.

#8 @bor0
7 months ago

Thank you @lukecavanagh. Please take a look at #40168 also.

#9 @johnbillion
7 months ago

  • Keywords commit added; ux-feedback good-first-bug removed
  • Milestone changed from Awaiting Review to 4.8
  • Version 4.7.3 deleted

#10 @johnbillion
7 months ago

  • Owner set to johnbillion
  • Status changed from new to accepted

#11 @johnbillion
7 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 40323:

Users: Don't push the current user's role to the top of the list in wp_dropdown_roles().

This brings consistency to the order in which roles are displayed in the Roles dropdown when editing users.

Props bor0

Fixes #40162

Note: See TracTickets for help on using tickets.