[Feature] Implement plugin permissions management system#343
Draft
HILAYTRIVEDI wants to merge 2 commits intoWordPress:developfrom
Draft
[Feature] Implement plugin permissions management system#343HILAYTRIVEDI wants to merge 2 commits intoWordPress:developfrom
HILAYTRIVEDI wants to merge 2 commits intoWordPress:developfrom
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #343 +/- ##
=============================================
- Coverage 57.85% 56.60% -1.25%
- Complexity 615 652 +37
=============================================
Files 46 48 +2
Lines 3165 3339 +174
=============================================
+ Hits 1831 1890 +59
- Misses 1334 1449 +115
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
What?
Closes #342
Why?
The plugin-level permissions and provider routing feature introduced three new production classes (
Permissions_Manager,Plugin_Registry) and extendedAI_Service,Settings_Page,Settings_Registration,bootstrap.php, andhelpers.phpwith no test coverage. Without tests, regressions in access control logic e.g. the global toggle blocking all access, the opt-in default, provider preference filtering would go undetected.What changed?
Production code
includes/Permissions/Permissions_Manager.php(new) Singleton that gates plugin AI access (plugin_has_access()), stores and retrieves per-plugin provider routing preferences (get_plugin_provider_preferences()), and sanitizes plugin IDs for use as option-name suffixes (sanitize_option_key()). Fires thewpai_register_pluginsaction oninitialize().includes/Permissions/Plugin_Registry.php(new) In-memory registry for plugins that declare themselves as AI consumers viawpai_register_plugins. Exposesregister_plugin()(no-op on duplicate),get_all_plugins(),get_plugin(), andhas_plugin().includes/Services/AI_Service.phpAddedcreate_textgen_prompt_for_plugin(): performs an access check viaPermissions_Manager, then builds a prompt scoped to the plugin's provider preferences (falls back to global if none configured).includes/Settings/Settings_Page.phpAddedrender_plugin_permissions_section(): renders an admin UI card with per-plugin access toggles and provider routing text inputs. Section is hidden when no plugins are registered; inputs are disabled when the global AI toggle is off.includes/Settings/Settings_Registration.phpAddedregister_plugin_permission_settings()(registerswpai_plugin_access_*andwpai_plugin_providers_*options per plugin) andsanitize_provider_preferences()(sanitizes comma-separated provider slug lists via
sanitize_key()).includes/bootstrap.phpCallsPermissions_Manager::get_instance()->initialize()during plugin load so registrations viawpai_register_pluginsare processed in time.includes/helpers.phpAdded the public helperplugin_has_ai_access( $plugin_id )as a thin wrapper aroundPermissions_Manager::plugin_has_access().Tests
Added two new integration test files and extended the existing
AI_ServiceTest:tests/Integration/Includes/Permissions/Plugin_RegistryTest.php11 tests coveringregister_plugin()(data storage, name/description defaults, duplicate no-op, XSS sanitization viasanitize_text_field/sanitize_textarea_field),get_all_plugins(),get_plugin(), andhas_plugin().tests/Integration/Includes/Permissions/Permissions_ManagerTest.php17 tests covering the singleton (get_instance()),initialize()idempotency and action firing,plugin_has_access()(global toggle off, unregistered plugin, not granted, granted, filter override, filter receives correct plugin ID),get_plugin_provider_preferences()(empty default, stored slugs, whitespace trimming, empty segment pruning, filter override), andsanitize_option_key()(lowercasing, special-character replacement, valid-character preservation).tests/Integration/Includes/Services/AI_ServiceTest.php5 new tests forcreate_textgen_prompt_for_plugin()covering all denial paths (unregistered plugin, global AI disabled, access not granted) and the success paths (access granted with prompt string, access granted with null prompt).All tests follow the project's
WP_UnitTestCaseconventions: WordPressupdate_option/delete_optionfor state,@coverstags,@since 1.0.0aligned with the production code, and action/filter hooks cleaned up after each assertion to ensure determinism.Testing Instructions
WP_TESTS_DIRor equivalent).tests/Integration/Includes/Permissions/pass with nofailures or warnings.
tests/Integration/Includes/Services/AI_ServiceTest.php.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Used for: Initial test scaffolding (method names, assertion structure,
setUp/tearDown shape). Final tests were reviewed line-by-line, corrected for hook
cleanup (leaked
add_actioncallbacks replaced with stored references +remove_action), docblock style aligned to project conventions (Tests that…descriptions,
@covers, third-person setUp/tearDown descriptions), and verifiedagainst all production source files before submission.
Testing Instructions for Keyboard
N/A no UI changes.
Screenshots or screencast
N/A test-only change.