Connectors: Type-agnostic registry with explicit key configuration#11363
Connectors: Type-agnostic registry with explicit key configuration#11363jorgefilipecosta wants to merge 6 commits intoWordPress:trunkfrom
Conversation
…e detection
Some connectors use established PHP constants or environment variables
that don't follow the default {UPPER_ID}_API_KEY naming convention.
This adds optional constant_name and env_var_name fields to the
connector authentication config so key source detection works correctly
regardless of naming conventions.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
The default setting_name used connectors_ai_ prefix regardless of
connector type. Now uses the connector type in the prefix:
ai_provider → connectors_ai_, other types → connectors_{type}_,
no type → connectors_.
- Default setting_name is now connectors_{type}_{id}_api_key with no
special cases
- Built-in AI connectors explicitly declare setting_name, constant_name,
and env_var_name
- Third-party AI providers get explicit names at registration time
- constant_name/env_var_name are truly optional: only checked when
provided, no auto-derivation from connector ID
- _wp_connectors_get_api_key_source simplified: removed $connector_id
param and all auto-derivation logic
- Add explicit setting_name to default test args and mock provider
to match how built-in AI connectors now declare their names
- Update default-generation test assertions to expect the new
connectors_{type}_{id}_api_key format
- Widen PHPStan type from 'ai_provider' to non-empty-string - REST dispatch: mask keys for all connector types, validate only AI - Settings registration: register for all types, skip already-registered - Script module: type-aware isConnected logic, add pluginFile field - Add method_exists() guards for AI registry metadata methods
Trac Ticket MissingThis pull request is missing a link to a Trac ticket. For a contribution to be considered, there must be a corresponding ticket in Trac. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. More information about contributing to WordPress on GitHub can be found in the Core Handbook. |
Summary
Makes the connectors system support arbitrary connector types (not just
ai_provider), while keeping AI-specific behavior where needed.Registry & types
typefield widened from'ai_provider'tonon-empty-stringsetting_nameusesconnectors_{type}_{id}_api_keypatternsetting_name,constant_name, andenv_var_nameconstant_nameandenv_var_nameare truly optional — only checked when providedREST dispatch
Settings registration
api_keyauthai_providertype onlyScript module data
isConnected: AI providers check the AI Client registry; others check key presencepluginFilefield to plugin datamethod_exists()guards on AI provider metadata methodsTest plan