Skip to content

fix(users): honour selected role on bulk user generation - #229

Merged
bordoni merged 1 commit into
mainfrom
fix/216-user-role-subscriber
Jul 16, 2026
Merged

fix(users): honour selected role on bulk user generation#229
bordoni merged 1 commit into
mainfrom
fix/216-user-role-subscriber

Conversation

@bordoni

@bordoni bordoni commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Fixes #216
Closes #217 (recreates @faisalahammad's fix on top of current main so it picks up the CI fix, plus regression tests, the site-default-role fallback, and the changelog entry — full credit via Co-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.php registered a singular role arg with default => subscriber. WP REST merges that default into every request, and the translate block copied it over the admin form's plural roles value. Same class of bug as Posts post_types (#210) and Terms taxonomy (#218/#227).

Fix

  • Endpoint: prefer the plural roles, accept singular role as a deprecated alias, normalise arrays to a comma-separated string, and drop the subscriber default (the fix from fix(users): honour selected role on bulk user generation #217).
  • Module: default the split request values (no more explode(null)) and, when no valid role is requested, fall back to get_option( 'default_role' ) — so the site's default role is respected instead of a hard-coded Subscriber.

Tests

UsersEndpointTest: plural roles assigns the selected role, plural wins over the singular alias, CSV roles samples across roles, and an unspecified role uses the site's configured default.

Milestone: 0.9.2

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>
@bordoni bordoni added this to the 0.9.2 milestone Jul 16, 2026
@bordoni
bordoni merged commit 5bda9bc into main Jul 16, 2026
3 of 5 checks passed
@bordoni
bordoni deleted the fix/216-user-role-subscriber branch July 16, 2026 15:17
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.

Bulk user generation always assigns “Subscriber” role regardless of selected role

1 participant