Make WordPress Core

Opened 14 months ago

Last modified 3 months ago

#58103 reviewing enhancement

Show user roles when deleting users

Reported by: presskopp's profile Presskopp Owned by: audrasjb's profile audrasjb
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Users Keywords: has-patch changes-requested dev-feedback has-screenshots needs-testing
Focuses: Cc:

Description

When deleting an admin user, who has published something before, you will be asked to transfer the ownership of posts:

Attribute all content to:

Then there's a list with ALL users of the site, having all sorts of roles and therefore it can be huge.

My proposal is to somehow differenciate between user roles here so one can easily pick another admin.

Attachments (2)

Capture d’écran 2023-06-26 à 20.19.20.png (185.2 KB) - added by audrasjb 11 months ago.
Before patch
Capture d’écran 2023-06-26 à 20.22.16.png (196.9 KB) - added by audrasjb 11 months ago.
After patch: we loose the user slug

Download all attachments as: .zip

Change History (39)

#2 @lopo
13 months ago

  • Keywords needs-patch added

It would make sense to me, but it looks like we'd need to change the underlying wp_dropdown_users() function.
The easiest thing would probably be adding a value for the show parameter to e.g. display Display Name (login_name) - role.
A smarter and more versatile choice could be adding a bool group_by_role parameter to display users grouped in one <outgroup> for each role.

This ticket was mentioned in PR #4330 on WordPress/wordpress-develop by @madejtax.


13 months ago
#3

  • Keywords has-patch added; needs-patch removed

Trac ticket:

This ticket was mentioned in PR #4331 on WordPress/wordpress-develop by @madejtax.


13 months ago
#4

Trac ticket:

#5 @SergeyBiryukov
13 months ago

  • Milestone changed from Awaiting Review to 6.3

#6 @lphoumpakka
13 months ago

Hello @madejtax,

The patch is working as expected.
I left comments in the PR: https://github.com/WordPress/wordpress-develop/pull/4331

#7 @pooja1210
13 months ago

Hi,

Tested the patch and the patch is working fine. https://github.com/WordPress/wordpress-develop/pull/4331

The user roles are visible in Attribute all content to dropdown.

Just noticed that: role is visible as rol. I think it should be role.

Reference: https://prnt.sc/DjdnLZwy274b

Thanks!

@hztyfoon commented on PR #4331:


13 months ago
#8

Looks like there are some coding standards issues in the file changes. Can u fix them?

#9 @hztyfoon
13 months ago

Looks like the PR https://github.com/WordPress/wordpress-develop/pull/4331 is failing some coding standard tests.

#10 @madejtax
12 months ago

Sorry, I made the changes and they would already be in the corresponding branch.

https://github.com/madejtax/wordpress-develop/tree/Changes-when-deleting-a-user-ticket-58103

I need to create the pull request, currently github is giving me a bug, when I solve it I will make the pull request.

This ticket was mentioned in PR #4441 on WordPress/wordpress-develop by @madejtax.


12 months ago
#11

Trac ticket: #58103

#12 @madejtax
12 months ago

I have a problem with PHPCS, the case is that it is giving me an error in a line that has no problem...

https://github.com/WordPress/wordpress-develop/commit/2b6662ec7f8135de50716c78fa53b92322c3c7ac

As you can see, I've already had several pulls.... But it still gives the same problem

Version 0, edited 12 months ago by madejtax (next)

#13 follow-up: @pooja1210
12 months ago

Hi,

Test Report for patch - https://github.com/WordPress/wordpress-develop/pull/4441

Environment:
WordPress- 6.2
Device- Mac
Browser: Chrome

Expected Result: The user roles should be visible in Attribute all content to: dropdown while deleting the user ☑️

Screenshots:
https://prnt.sc/pQOJk5TG9vX2

However, @madejtax can we update the 'role' in dropdown to 'Role'. Make first letter capitalize.
Other than this rest looks fine to me.

Thanks!

#14 in reply to: ↑ 13 @madejtax
12 months ago

Modified, ready to implement

Replying to pooja1210:

Hi,

Test Report for patch - https://github.com/WordPress/wordpress-develop/pull/4441

Environment:
WordPress- 6.2
Device- Mac
Browser: Chrome

Expected Result: The user roles should be visible in Attribute all content to: dropdown while deleting the user ☑️

Screenshots:
https://prnt.sc/pQOJk5TG9vX2

However, @madejtax can we update the 'role' in dropdown to 'Role'. Make first letter capitalize.
Other than this rest looks fine to me.

Thanks!

@audrasjb commented on PR #4331:


12 months ago
#15

Closed in favor of #4441

#16 @oglekler
11 months ago

  • Keywords close added

@audrasjb
11 months ago

After patch: we loose the user slug

#17 follow-up: @audrasjb
11 months ago

  • Keywords changes-requested added; close removed
  • Owner set to audrasjb
  • Status changed from new to reviewing

The patch looks almost good to me, but I wonder why the username (slug) was removed?
Also I don't think we need to add the strings "User:" and "Role:". And if we want to keep these string, they should at least be translatable.

Please note that tomorrow is 6.3 beta 1. Without a patch ready to go we will probably move this to the next milestone, 6.4 :)

#18 in reply to: ↑ 17 @madejtax
11 months ago

What do you think of this second option?

Where do I show the user's name, slug and role?

Edit: Edit: I thought it was a bit silly to show the name instead of the slug, in the end when you have the user you already know what name he/she has.

https://i.imgur.com/ymstbkD.png
Replying to audrasjb:

The patch looks almost good to me, but I wonder why the username (slug) was removed?
Also I don't think we need to add the strings "User:" and "Role:". And if we want to keep these string, they should at least be translatable.

Please note that tomorrow is 6.3 beta 1. Without a patch ready to go we will probably move this to the next milestone, 6.4 :)

Last edited 11 months ago by madejtax (previous) (diff)

This ticket was mentioned in PR #4703 on WordPress/wordpress-develop by @madejtax.


11 months ago
#19

Trac ticket:

#20 follow-ups: @audrasjb
11 months ago

Hey thanks for updating the patch @madejtax!

As there is not much time before 6.3 beta 1 I'd recommend to simplify the patch and to keep it as close as possible to the current behavior.

Here is what I suggest:

"Display Name (username) - administrator"

echo '<option value="' . esc_attr( $user->ID ) . '">' . esc_html( $user->display_name ) . ' (' . esc_html( $user->user_login ) . ') - ' . esc_html( $user->roles[0] ) . '</option>';

#21 in reply to: ↑ 20 @ocean90
11 months ago

Replying to audrasjb:

Make sure to use translate_user_role() for displaying role names.

#22 in reply to: ↑ 20 @madejtax
11 months ago

Here is the change as they say commented

https://github.com/WordPress/wordpress-develop/pull/4703/commits/8f4b16a82833fd8ce83057ac3b175a41fd2a33e2

Replying to audrasjb:

Hey thanks for updating the patch @madejtax!

As there is not much time before 6.3 beta 1 I'd recommend to simplify the patch and to keep it as close as possible to the current behavior.

Here is what I suggest:

"Display Name (username) - administrator"

echo '<option value="' . esc_attr( $user->ID ) . '">' . esc_html( $user->display_name ) . ' (' . esc_html( $user->user_login ) . ') - ' . esc_html( $user->roles[0] ) . '</option>';

This ticket was mentioned in Slack in #core by chaion07. View the logs.


11 months ago

#25 follow-up: @audrasjb
11 months ago

  • Keywords dev-feedback added
  • Milestone changed from 6.3 to 6.4

Thanks!
However, I have a small concern about $user->roles[0] because on many websites, users can have several roles.

As per today's bug scrub and since WP 6.3 beta 1 is scheduled today, let's move this ticket to milestone 6.4 to give it more time for discussion/feedback.

#26 follow-up: @Presskopp
11 months ago

  • Keywords has-screenshots added

I was even thinking of something like:

https://i.imgur.com/pYpYbMP.png

#27 in reply to: ↑ 26 @knutsp
11 months ago

Replying to Presskopp:

I was even thinking of something like:

https://i.imgur.com/pYpYbMP.png

Nice, but then every WP_Role object, including custom ones, need a plural label for translation.

#28 in reply to: ↑ 25 @knutsp
11 months ago

Replying to audrasjb:

Thanks!
However, I have a small concern about $user->roles[0] because on many websites, users can have several roles.

Ordering them alpabetically will not work well for all languages, so I suggest keep it simple. But if not simple, indicate it. That means show first one, then suffix it with '(+n)' when necessary where n = count(roles).

And don't forget no role situation.

#29 @oglekler
9 months ago

@madejtax can you please look through the suggestions and concerns above? This is an enhancement and to land it into 6.4, it needs to be in Trunk before Beta 1. Thank you 🙏

#30 @oglekler
8 months ago

I wonder if a better approach will be to create a new function wp_dropdown_users_with_roles() instead of the current approach, this way it can be used elsewhere if needed. And patch cannot be applied, there are changes in wp_dropdown_users() arguments.

This ticket was mentioned in Slack in #core by oglekler. View the logs.


8 months ago

#32 @oglekler
8 months ago

  • Milestone changed from 6.4 to 6.5

This ticket was discussed during bug scrub.

Due to lack of activity lately and some changes that needs to be done, I am moving it into the next milestone.

Add props to @mukesh27

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 months ago

#34 @audrasjb
4 months ago

  • Keywords needs-testing added

As per today's bug scrub: we have a PR but it still needs some testing/refinement to make sure it works well with multiple roles.

#35 @huzaifaalmesbah
3 months ago

i try to test but PR not working. i think need refresh.

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


3 months ago

#37 @audrasjb
3 months ago

  • Milestone changed from 6.5 to Future Release

As per today's bug scrub, moving this ticket to Future Release as we still need some work and testing.

Note: See TracTickets for help on using tickets.