Skip to content

Add user access controls to each feature - #1297

Merged
dkotter merged 10 commits into
WordPress:developfrom
dkotter:feature/user-access-controls
Nov 18, 2026
Merged

dkotter merged 10 commits into
WordPress:developfrom
dkotter:feature/user-access-controls

Conversation

@dkotter

@dkotter dkotter commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #736. Supersedes #749. Props @Infinite-Null, whose settings UI and other work from #749 is carried over here.

Adds per-feature access controls. Admins can restrict each supported AI feature to chosen roles and/or specific users. The restriction is enforced wherever the feature's abilities run, not only in the plugin's own UI.

Why?

Site owners asked how to limit AI features to certain roles or users (support thread). #749 built the UI and the settings, but it linked abilities to features by guessing the feature from the ability's name. It also changed Abstract_Feature::register() in a way that broke existing subclasses. This PR keeps the agreed UX and behavior from #749, and reworks the structure so that abilities stay general building blocks with no knowledge of features.

How?

  • Policy is a meta capability. current_user_can( 'wpai_use_feature', $feature_id ), mapped in Feature_Access::map_meta_cap(). Sites can extend it with the standard map_meta_cap / user_has_cap filters. It is backed by three options per feature: wpai_feature_{id}_access_control_enabled, _roles, _users.
  • The feature owns its abilities' restriction. Features register abilities through Abstract_Feature::register_feature_ability(), which adds meta['wpai_feature'] to the ability. Ability classes never know about features. An ability someone registers directly with wp_register_ability() is not tied to any feature.
  • Enforcement on every path. Feature_Access hooks core's wp_ability_permission_result filter, so tagged abilities are denied on REST, batch, MCP over HTTP, runAbility() and direct execute().
    • The gate only narrows access. It can never grant. On WP 7.0.x, Abstract_Ability::check_permissions() back-fills the filter. That polyfill is generic and can be removed once the minimum WordPress version is 7.1.
  • UI hooks. There is an optional Abstract_Feature::register_ui(). The Loader calls it only for users with access, or for everyone when a feature has not opted in. register() stays abstract and unchanged, so there's no breaking change for existing features.
  • Opt-in. Features opt in with 'access_control' => true metadata. All built-in editor features opt in, as do Comment Moderation and Suggest Reply. Third-party features opt in once they adopt the helpers.
  • Backwards compatible. Access is identical to today while access control is off, and while it is on but not yet saved.
    • When an admin turns it on, Administrator and Editor are pre-checked. Saving applies those lists, which may be stricter than today.
    • The users list only ever grants access.
    • The settings live in a separate option group, so settings export/import excludes them.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Fable 5.1 (design, plan, orchestration, verification), Claude Opus 5.5 (implementation and reviews), Claude Sonnet 5.5 (small re-reviews)
Used for: Reviewing #749, designing the revised structure, implementing it task by task with an independent review after each task, and a whole-branch review. I reviewed and committed each task myself.

Testing Instructions

  1. Enable a few editor features, for example Title Generation and Image Generation.
  2. Turn on Developer Tools → Access controls. Each enabled feature that supports it now shows "Enable access control".
  3. Turn it on for Title Generation. Administrator and Editor are pre-checked. Before you save, confirm that an Author can still generate titles.
  4. Click Save without changing anything. Then:
    • As an Author, the Title Generation UI is gone.
    • As an Author, wp.apiFetch( { path: '/wp-abilities/v1/abilities/ai/title-generation/run', method: 'POST', data: { input: { post_id: <id> } } } ) returns 403 with wpai_feature_access_denied.
    • As an Editor, both still work.
  5. Add the Author by name in Users and save. The Author regains access.
  6. Uncheck every role, with no users listed, and save. Nobody has access, including administrators.
  7. Turn off the Access controls view. The feature card shows "Access restricted to selected roles and users."
  8. Turn access control off for the feature and save. Everyone has the same access as before.
  9. Export settings and confirm no _access_control_enabled, _roles or _users keys are included.

Screenshots or screencast

Screenshot 2026-11-05 at 2 22 08 PM Screenshot 2026-11-05 at 2 22 21 PM Screenshot 2026-11-05 at 2 22 29 PM

Changelog Entry

Added - Role and user based access controls for features and experiments.

Open WordPress Playground Preview

…pai_use_feature capability. Backfill the core wp_ability_permission_result filter
…istering things, with new methods to register UI and abilities. Ensure oure Loader runs the necessary methods if a user has access
Co-authored-by: Infinite-Null <ankitkumarshah@git.wordpress.org>
…om experiments. Fix failing tests on WP 7. Some UI fixes around saved/not saved state
@dkotter dkotter added this to the 1.6.0 milestone Nov 5, 2026
@dkotter dkotter self-assigned this Nov 5, 2026
@dkotter
dkotter requested a review from a team November 5, 2026 21:23
@dkotter
dkotter requested a review from jeffpaul as a code owner November 5, 2026 21:23
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dkotter <dkotter@git.wordpress.org>
Co-authored-by: jeffpaul <jeffpaul@git.wordpress.org>
Co-authored-by: Infinite-Null <ankitkumarshah@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.38462% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.58%. Comparing base (5a1f305) to head (f714e89).

Files with missing lines Patch % Lines
includes/Settings/Settings_Page.php 52.17% 11 Missing ⚠️
includes/Access_Control/Feature_Access.php 86.66% 6 Missing ⚠️
...udes/Experiments/Text_To_Speech/Text_To_Speech.php 66.66% 3 Missing ⚠️
includes/Settings/Settings_Registration.php 95.38% 3 Missing ⚠️
includes/Abstracts/Abstract_Ability.php 66.66% 2 Missing ⚠️
...iments/Alt_Text_Generation/Alt_Text_Generation.php 81.81% 2 Missing ⚠️
...des/Experiments/Text_To_Speech/REST_Controller.php 87.50% 2 Missing ⚠️
...eriments/Comment_Moderation/Comment_Moderation.php 85.71% 1 Missing ⚠️
.../Content_Classification/Content_Classification.php 85.71% 1 Missing ⚠️
.../Experiments/Content_Resizing/Content_Resizing.php 85.71% 1 Missing ⚠️
... and 9 more
Additional details and impacted files
@@              Coverage Diff              @@
##             develop    #1297      +/-   ##
=============================================
+ Coverage      85.56%   85.58%   +0.01%     
- Complexity      5003     5087      +84     
=============================================
  Files            192      193       +1     
  Lines          18205    18409     +204     
=============================================
+ Hits           15578    15755     +177     
- Misses          2627     2654      +27     
Flag Coverage Δ
unit 85.58% <87.38%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

jeffpaul
jeffpaul previously approved these changes Nov 10, 2026
@jeffpaul

Copy link
Copy Markdown
Member

@dkotter a rebase / merge conflict fix should be good to get this ready for merge

@dkotter
dkotter merged commit 520d656 into WordPress:develop Nov 18, 2026
35 checks passed
@dkotter
dkotter deleted the feature/user-access-controls branch November 18, 2026 18:23
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.

Expose role/user access controls per feature/experiment

2 participants