feat(providers): add WpCapabilityProvider (v1.3.0) - #12
Merged
Merged
Conversation
Gates resources by one or more WordPress capability slugs (install_plugins, edit_posts, manage_options, etc.). Options are discovered dynamically across every role returned by wp_roles() so plugin-registered caps (WooCommerce, Members, User Role Editor) appear automatically. Access is granted when user_can() returns true for any selected capability. - src/WpCapabilityProvider.php — new provider class with wp_capability ID, dynamic options, ANY-match semantics, and two filters (wpb_access_control_wp_capability_options, wpb_access_control_wp_capability_has_access) - src/AccessControlManager.php — registered as a default provider - js/components/RoleOptionsPanel.js — description string for wp_capability; existing checkbox panel renders the new options automatically - tests/Unit/WpCapabilityProviderTest.php — 21 new tests (identity, dedup, sort, falsy-cap skip, malformed roles, filter override, ANY-match short-circuit, empty-string skip, filter cast) - README.md / CHANGELOG.md — documented new provider, dropdown row, and filters PHPUnit: 116 tests / 172 assertions all green. JS assets rebuilt via wp-scripts. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wp_capability), so the React UI's Who can access dropdown can gate a resource by one or more WordPress capability slugs (install_plugins,edit_posts,manage_options, …)wp_roles()— plugin-registered caps (WooCommerce, Members, User Role Editor) appear automaticallyWpRoleProvider: a user passes whenuser_can()returnstruefor any selected capability; admins bypass unconditionallywpb_access_control_wp_capability_options(UI list) andwpb_access_control_wp_capability_has_access(final decision)Changes
src/WpCapabilityProvider.php— new provider classsrc/AccessControlManager.php— registered alongsidewp_role/wp_userjs/components/RoleOptionsPanel.js— UI subtitle forwp_capabilitytests/Unit/WpCapabilityProviderTest.php— 21 new testsassets/build/index.js— rebuilt viawp-scripts buildREADME.md/CHANGELOG.md— documentedTest plan
composer test— 116 tests / 172 assertions, all greennpm run build— wp-scripts compiles cleanlyinstall_plugins→ save; verifyGET /wpb-ac/v1/rules/{ns}/{key}returns{"key":"wp_capability","value":["install_plugins"]}install_pluginscap added passes🤖 Generated with Claude Code