Skip to content

Connectors: Type-agnostic registry with explicit key configuration#11363

Open
jorgefilipecosta wants to merge 6 commits intoWordPress:trunkfrom
jorgefilipecosta:add/connector-custom-key-names
Open

Connectors: Type-agnostic registry with explicit key configuration#11363
jorgefilipecosta wants to merge 6 commits intoWordPress:trunkfrom
jorgefilipecosta:add/connector-custom-key-names

Conversation

@jorgefilipecosta
Copy link
Copy Markdown
Member

@jorgefilipecosta jorgefilipecosta commented Mar 26, 2026

Summary

Makes the connectors system support arbitrary connector types (not just ai_provider), while keeping AI-specific behavior where needed.

Registry & types

  • PHPStan type field widened from 'ai_provider' to non-empty-string
  • Default setting_name uses connectors_{type}_{id}_api_key pattern
  • Built-in AI connectors pass explicit setting_name, constant_name, and env_var_name
  • constant_name and env_var_name are truly optional — only checked when provided

REST dispatch

  • Masks API keys for all connector types (not just AI)
  • Validates keys on update only for AI providers; non-AI connectors skip validation

Settings registration

  • Registers settings for all connector types with api_key auth
  • Skips settings already registered by the connector's own plugin
  • AI provider registry check scoped to ai_provider type only

Script module data

  • Type-aware isConnected: AI providers check the AI Client registry; others check key presence
  • Adds pluginFile field to plugin data
  • method_exists() guards on AI provider metadata methods

Test plan

  • Verify existing connector unit tests pass
  • Confirm AI provider connectors still validate keys on save
  • Confirm non-AI connectors can register and have keys masked in REST

…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.
@github-actions
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. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jorgefilipecosta.

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

@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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_.
@jorgefilipecosta jorgefilipecosta changed the title Connectors: Allow custom env var and constant names for key source detection Connectors: Allow custom env var, constant names, and type-aware default setting names Mar 26, 2026
@jorgefilipecosta jorgefilipecosta changed the title Connectors: Allow custom env var, constant names, and type-aware default setting names Connectors: Explicit key names and type-aware default setting names Mar 27, 2026
- 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
@jorgefilipecosta jorgefilipecosta changed the title Connectors: Explicit key names and type-aware default setting names Connectors: Type-agnostic registry with explicit key configuration Mar 27, 2026
@github-actions
Copy link
Copy Markdown

Trac Ticket Missing

This 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.

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.

1 participant