Repository navigation
Add user access controls to each feature - #1297
Conversation
…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
…ross all needed features
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
|
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. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@dkotter a rebase / merge conflict fix should be good to get this ready for merge |
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?
current_user_can( 'wpai_use_feature', $feature_id ), mapped inFeature_Access::map_meta_cap(). Sites can extend it with the standardmap_meta_cap/user_has_capfilters. It is backed by three options per feature:wpai_feature_{id}_access_control_enabled,_roles,_users.Abstract_Feature::register_feature_ability(), which addsmeta['wpai_feature']to the ability. Ability classes never know about features. An ability someone registers directly withwp_register_ability()is not tied to any feature.Feature_Accesshooks core'swp_ability_permission_resultfilter, so tagged abilities are denied on REST, batch, MCP over HTTP,runAbility()and directexecute().Abstract_Ability::check_permissions()back-fills the filter. That polyfill is generic and can be removed once the minimum WordPress version is 7.1.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.'access_control' => truemetadata. All built-in editor features opt in, as do Comment Moderation and Suggest Reply. Third-party features opt in once they adopt the helpers.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
wp.apiFetch( { path: '/wp-abilities/v1/abilities/ai/title-generation/run', method: 'POST', data: { input: { post_id: <id> } } } )returns 403 withwpai_feature_access_denied._access_control_enabled,_rolesor_userskeys are included.Screenshots or screencast
Changelog Entry