fix(users): honour selected role on bulk user generation - #217
Closed
faisalahammad wants to merge 1 commit into
Closed
fix(users): honour selected role on bulk user generation#217faisalahammad wants to merge 1 commit into
faisalahammad wants to merge 1 commit into
Conversation
- Prefer roles (plural, from admin form) over role (singular REST alias) - Remove default subscriber from schema so WP REST does not inject it - Normalize array and string values with sanitize_key and sanitize_text_field The endpoint previously unconditionally overwrote the form value with the schema default, causing all generated users to get the Subscriber role regardless of what was selected. Fixes bordoni#216
bordoni
added a commit
that referenced
this pull request
Jul 16, 2026
The Terms endpoint registered a singular 'taxonomy' arg with a hard-coded 'category' default, which WP REST injects into every request; the old translate block then copied that default over the admin form's plural 'taxonomies' value, so every term landed in 'category' regardless of the Tags/Categories selection. Prefer the plural 'taxonomies' value, accept the singular 'taxonomy' as an alias, normalise arrays to a comma-separated string, and drop the schema default. Mirrors the Posts #210 and Users #217 fixes. Fixes #218
Owner
|
Thank you for this fix, @faisalahammad! 🙏 Your change is spot-on. To land it in the 0.9.2 milestone I recreated it on top of the current |
Contributor
Author
|
Thank you so much @bordoni for the update and for including me in the credit! I’m really glad to see the fix merged and appreciate all the extra work you put into it. Looking forward to contributing more to FakerPress! 😊 |
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.
Summary
The Users REST endpoint was silently overwriting the admin form's selected role with a hard-coded
subscriberdefault. Every bulk user generation run produced Subscriber-only users regardless of what the admin picked (or what role was set as the site default). This PR mirrors the fix landed in #210 for the Posts endpoint: prefer the pluralrolesvalue from the form, accept the singularrolealias for REST callers, normalize arrays to comma-separated strings, and drop the schema default that was causing the override.Fixes #216
Changes
src/FakerPress/REST/Endpoints/Users.phpBefore:
After:
Why: WP REST merges the
defaultvalue into every request, so$params['role']was alwayssubscriber. The old normalization block then unconditionally copied that into$params['roles'], which is what the User module reads. Now the plural form value wins, arrays are coerced, slugs are sanitized, and the singular alias remains available for direct REST callers.Testing
Test 1: Single role from the admin form
Administratorin the Roles dropdown.Test 2: Multiple roles from the admin form
Editor+Author.Test 3: Direct REST call with the plural
rolesTest 4: Direct REST call with the singular
rolealias (backwards compatible)Result in all four cases: generated users receive the requested role(s); no more Subscriber override.
Screen recording
FakerPress-user-role-fix.mov