fix(users): honour selected role on bulk user generation - #229
Merged
Conversation
The Users endpoint registered a singular 'role' arg defaulting to 'subscriber', which WP REST injected into every request and the translate block copied over the admin form's plural 'roles' value, so bulk generation always produced Subscribers. Prefer the plural 'roles', accept 'role' as a deprecated alias, normalise arrays to a comma-separated string, and drop the schema default. The User module now defaults its split values and falls back to the site's configured default role when none is requested. Adds regression coverage. Based on the fix proposed in #217 by @faisalahammad. Fixes #216 Closes #217 Co-authored-by: Faisal Ahammad <13257516+faisalahammad@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #216
Closes #217 (recreates @faisalahammad's fix on top of current
mainso it picks up the CI fix, plus regression tests, the site-default-role fallback, and the changelog entry — full credit viaCo-authored-by).Problem
Bulk user generation always assigned Subscriber, regardless of the selected role or the site's Settings > General → New User Default Role.
Root cause
Users.phpregistered a singularrolearg withdefault => subscriber. WP REST merges that default into every request, and the translate block copied it over the admin form's pluralrolesvalue. Same class of bug as Postspost_types(#210) and Termstaxonomy(#218/#227).Fix
roles, accept singularroleas a deprecated alias, normalise arrays to a comma-separated string, and drop thesubscriberdefault (the fix from fix(users): honour selected role on bulk user generation #217).explode(null)) and, when no valid role is requested, fall back toget_option( 'default_role' )— so the site's default role is respected instead of a hard-coded Subscriber.Tests
UsersEndpointTest: pluralrolesassigns the selected role, plural wins over the singular alias, CSVrolessamples across roles, and an unspecified role uses the site's configured default.Milestone: 0.9.2