Skip to content

Ignore custom role keys in wp role reset --all - #91

Merged
swissspidy merged 1 commit into
mainfrom
claude/youthful-clarke-x3yxu6
Dec 3, 2026
Merged

swissspidy merged 1 commit into
mainfrom
claude/youthful-clarke-x3yxu6

Conversation

@swissspidy

@swissspidy swissspidy commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

wp role reset --all <custom-role> printed a PHP warning and reported a custom role as reset, even though custom roles aren't touched.

With --all, the default roles were appended to the role keys passed on the command line. A custom key passed alongside the flag therefore stayed in the list of roles to compare afterwards, but it never got a "before" snapshot. The $after[ $role_key ] != $before[ $role_key ] check then read an undefined array key (Warning: Undefined array key "custom-role"), counted the role as changed, and the summary was off.

Before this change:

$ wp role reset --all custom-role author
Custom role 'custom-role' not affected.
Restored 10 capabilities to and removed 0 capabilities from 'custom-role' role.
No changes necessary for 'author' role.
No changes necessary for 'administrator' role.
...
Success: 1 of 6 roles reset.

After:

$ wp role reset --all custom-role author
Custom role 'custom-role' not affected.
No changes necessary for 'administrator' role.
No changes necessary for 'editor' role.
No changes necessary for 'author' role.
No changes necessary for 'contributor' role.
No changes necessary for 'subscriber' role.
Success: No roles needed resetting.

--all always resets exactly the default roles, so the fix starts from an empty list in that branch instead of the user-supplied keys.

Testing

  • Added a step to the "Resetting a role" scenario in features/roles.feature that runs wp role reset --all custom-role author and asserts the output matches a plain --all with an empty STDERR. It fails without the fix and passes with it.
  • features/ passes locally (6 scenarios, 110 steps) with WP_CLI_TEST_DBTYPE=sqlite; PHPCS and gherkin-lint pass. PHPStan was not run locally.

Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed wp role reset --all when custom role names are also provided. Custom roles are excluded from the reset, while unchanged default roles are reported as before.
    • When no roles need resetting, the command now returns the aggregate “no roles needed resetting” result without writing to STDERR.

With `--all`, the default roles were appended to the user-supplied role
keys, so a custom key passed alongside the flag stayed in the list to
check. It had no recorded "before" state, which raised an "Undefined
array key" warning and counted the untouched custom role as reset.

`--all` always resets exactly the default roles, so start from an
empty list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UWTd5oVnmAsBjaCvdBJ8ax
@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When --all is set, Role_Command::reset() clears supplied role arguments before building the default role list. A feature test checks the command output when custom and default roles are supplied.

Changes: Role reset behavior

Layer / File(s) Summary
Clear arguments and verify reset output
src/Role_Command.php, features/roles.feature
When --all is set, the command clears supplied role arguments before processing default roles. The feature test checks the custom-role exclusion message, unchanged default-role messages, the aggregate result, and empty STDERR.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: schlessera, ernilambar

Merge Risk: Minimal · up to 63a99

This fixes wp role reset --all when custom role names are also supplied: the command no longer emits an undefined-key warning or counts a custom role as reset. The change is small and a feature test covers it, so merge risk is minimal.

Security architecture risk: Minimal · up to 63a99

With wp role reset --all, WordPress still resets the same default roles. Extra role names no longer produce misleading reset counts or an undefined-key warning. The change does not alter who can run the command or which roles it can modify.

Security review details

Security Blast Radius

  • observed — For a given invocation, the changed branch still passes only the five built-in role keys to remove_role(). Extra caller-supplied keys do not reach an additional role mutation.

Trust Boundaries and Controls

  • observed — The command still checks that the WordPress role registry is configured to persist before entering either reset branch. The new assignment changes a local list, not the caller's identity, execution privileges, or persistence configuration.

Dependencies

  • observed — The bulk reset still uses WordPress's role APIs and delegates repopulation to populate_roles(); the PR does not change that dependency or its call order.

Resilience and Maintainability Implications

  • observed — When execution reaches reporting, every compared key under --all now has a matching before entry. This fixes reporting for mixed arguments; it does not add atomicity, write acknowledgment, or recovery to the existing remove-then-repopulate sequence.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: wp role reset --all now ignores custom role keys passed as arguments. The raw summary says Role_Command::reset() starts $args as an empty array in the --all branch,…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: wp role reset --all now ignores custom role keys passed as arguments. The raw summary says Role_Command::reset() starts $args as an empty array in the --all branch, so only default roles are compared. The objectives describe the same fix for the undefined-array-key warning and the miscounted custom role. The title is specific and matches the main change.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 92326722-69d6-4137-9bbd-18ca198fafc7
Commits

Reviewing files that changed from the base of the PR and between 61f450f and 63a994c.

Files selected for processing: 2

  • features/roles.feature
  • src/Role_Command.php

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions github-actions Bot added bug command:role-reset Related to 'role reset' command labels Dec 3, 2026
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@swissspidy
swissspidy marked this pull request as ready for review December 3, 2026 15:44
@swissspidy
swissspidy requested a review from a team as a code owner December 3, 2026 15:44
Copilot AI balanced review requested due to automatic review settings December 3, 2026 15:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

There are no active review issues for the wp role reset --all fix.

No open issues 🎉

Review effort: Balanced

@swissspidy
swissspidy merged commit d69f8d4 into main Dec 3, 2026
60 checks passed
@swissspidy
swissspidy deleted the claude/youthful-clarke-x3yxu6 branch December 3, 2026 16:19
@github-actions github-actions Bot added this to the 3.0.3 milestone Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug command:role-reset Related to 'role reset' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants