Skip to content

Users: Disallow bulk editing user roles when only one user is available#8469

Closed
audrasjb wants to merge 3 commits intoWordPress:trunkfrom
audrasjb:63068
Closed

Users: Disallow bulk editing user roles when only one user is available#8469
audrasjb wants to merge 3 commits intoWordPress:trunkfrom
audrasjb:63068

Conversation

@audrasjb
Copy link
Copy Markdown
Contributor

@audrasjb audrasjb commented Mar 6, 2025

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props audrasjb, johnbillion.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@johnbillion
Copy link
Copy Markdown
Member

johnbillion commented Mar 6, 2025

I don't believe the number of users is the issue. The same thing occurs if you try to remove the role of your own admin account on a site where there are other users.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 6, 2025

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@audrasjb
Copy link
Copy Markdown
Contributor Author

audrasjb commented Mar 6, 2025

I don't believe the number of users is the issue. The same thing occurs if you try to remove the role of your own admin account on a site where there are other users.

I suspected this but I wanted to propose a first workaround and then investigate a bit more.

@audrasjb
Copy link
Copy Markdown
Contributor Author

audrasjb commented Mar 6, 2025

I edited the PR to change the conditional: it now checks whether the current user is trying to remove their own role.

@johnbillion
Copy link
Copy Markdown
Member

johnbillion commented Mar 12, 2025

The underlying problem is that there is logic for this already, in https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-admin/users.php#L146-L153, but it only accounts for a user attempting to change their own role to one that doesn't have the promote_users capability. It doesn't account for a user attempting to remove their role (and is the cause of the error reported in the ticket).

I think the existing condition should be updated or extended to account for an attempt to remove the role, rather than introducing separate logic prior to iterating the list of users.

@github-actions
Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 62026
GitHub commit: debd1f5

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions bot closed this Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants