Skip to content

Fix: Adding multiple roles in edit user page is not updating after saving#407

Open
reygcalantaol wants to merge 3 commits intodevelopfrom
406-Adding-multiple-roles-in-edit-user-page-is-not-updating-after-saving-
Open

Fix: Adding multiple roles in edit user page is not updating after saving#407
reygcalantaol wants to merge 3 commits intodevelopfrom
406-Adding-multiple-roles-in-edit-user-page-is-not-updating-after-saving-

Conversation

@reygcalantaol
Copy link
Copy Markdown
Collaborator

@reygcalantaol reygcalantaol commented Jun 15, 2025

Resolves #406

Summary

Fixes the multiple roles field not appearing on the Edit User page (user-edit.php). The wpum_user_roles Carbon Field was only registered when $pagenow === 'user-new.php', so editing an existing user's roles silently failed.

Fix: Change 'user-new.php' === $pagenow to in_array( $pagenow, array( 'user-new.php', 'user-edit.php' ) ).


Manual Test Plan

Prerequisites

  • WP User Manager active
  • Go to Users > Settings > Profiles and enable Allow Multiple User Roles

1. Verify roles field appears on Edit User

  • Go to Users > All Users and click Edit on any user
  • Scroll to the Profile Privacy section (Carbon Fields meta box)
  • Expected: A multi-select roles field appears showing the user's current roles

2. Add a role and save

  • On the Edit User page, add a second role (e.g. add "Editor" to a Subscriber)
  • Click Update User
  • Reload the page
  • Expected: Both roles are still selected — the change persisted

3. Remove a role and save

  • Remove one of the roles (go back to just Subscriber)
  • Click Update User
  • Reload the page
  • Expected: Only the remaining role is selected

4. Verify Add New User still works

  • Go to Users > Add New
  • Expected: The multi-select roles field also appears here (regression check)
  • Create a new user with multiple roles selected
  • Expected: The new user is created with both roles assigned

5. Verify disabled state

  • Go to Users > Settings > Profiles and disable Allow Multiple User Roles
  • Go back to Users > Edit on any user
  • Expected: The multi-select roles field is NOT shown

WPUnit Test Coverage

11 tests in tests/wpunit/Privacy/MultipleRolesFieldTest.php:

  • Function exists and is hooked to carbon_fields_register_fields
  • Executes without error on user-edit.php and user-new.php
  • in_array condition passes for both pages (the core fix)
  • Condition fails when option disabled or on unrelated pages
  • Condition passes with and without $profileuser set

🤖 Generated with Claude Code

@polevaultweb polevaultweb requested a review from Copilot July 5, 2025 14:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the multiple roles selector not appearing on the user edit page by updating the page-check condition to include user-edit.php.

  • Expanded the conditional to show the roles multiselect on both user creation and edit pages.
  • Ensured network admin screens are still excluded.

Comment thread includes/actions.php
);

if ( $allow_multiple_roles && ( $profileuser || 'user-new.php' === $pagenow ) && ! is_network_admin() ) {
if ( $allow_multiple_roles && ( $profileuser || in_array( $pagenow, array( 'user-new.php', 'user-edit.php' ) ) ) && ! is_network_admin() ) {
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the strict parameter in in_array (e.g., in_array($pagenow, ['user-new.php', 'user-edit.php'], true)) to ensure type-safe comparisons.

Suggested change
if ( $allow_multiple_roles && ( $profileuser || in_array( $pagenow, array( 'user-new.php', 'user-edit.php' ) ) ) && ! is_network_admin() ) {
if ( $allow_multiple_roles && ( $profileuser || in_array( $pagenow, array( 'user-new.php', 'user-edit.php' ), true ) ) && ! is_network_admin() ) {

Copilot uses AI. Check for mistakes.
Comment thread includes/actions.php
);

if ( $allow_multiple_roles && ( $profileuser || 'user-new.php' === $pagenow ) && ! is_network_admin() ) {
if ( $allow_multiple_roles && ( $profileuser || in_array( $pagenow, array( 'user-new.php', 'user-edit.php' ) ) ) && ! is_network_admin() ) {
Copy link

Copilot AI Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Extract the array of page names into a descriptive variable or constant (e.g., $role_pages = ['user-new.php', 'user-edit.php'];) to improve readability and simplify future updates.

Suggested change
if ( $allow_multiple_roles && ( $profileuser || in_array( $pagenow, array( 'user-new.php', 'user-edit.php' ) ) ) && ! is_network_admin() ) {
$role_pages = array( 'user-new.php', 'user-edit.php' );
if ( $allow_multiple_roles && ( $profileuser || in_array( $pagenow, $role_pages ) ) && ! is_network_admin() ) {

Copilot uses AI. Check for mistakes.
polevaultweb and others added 2 commits February 18, 2026 12:28
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.

Adding multiple roles in edit user page is not updating after saving.

3 participants