#64957 closed defect (bug) (fixed)
Connectors: `WP_Connector_Registry::register()` ignores custom `setting_name`
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | high |
| Severity: | normal | Version: | 7.0 |
| Component: | General | Keywords: | has-patch dev-reviewed has-unit-tests |
| Focuses: | Cc: |
Description
WP_Connector_Registry::register() always auto-generates the setting_name for connectors that use api_key authentication:
$connector['authentication']['setting_name'] = 'connectors_ai_' . str_replace( '-', '_', $id ) . '_api_key';
This ignores any setting_name value provided in the $args['authentication'] array, making it impossible for connectors to use an existing WordPress option (e.g. one already registered by their plugin) as their API key setting.
Steps to Reproduce
- Register a connector with a custom
setting_name:$registry->register( 'my-connector', array( 'name' => 'My Connector', 'type' => 'ai_provider', 'authentication' => array( 'method' => 'api_key', 'setting_name' => 'my_existing_option', ), ) ); - Retrieve the connector:
wp_get_connector( 'my-connector' ) - Inspect
$connector['authentication']['setting_name']
Expected Results
setting_name is my_existing_option (the caller-provided value).
Actual Results
setting_name is connectors_ai_my_connector_api_key (the auto-generated value). The custom value is silently discarded.
Proposed Fix
Check for a non-empty, string setting_name in the provided args before falling back to the auto-generated default:
- $connector['authentication']['setting_name'] = 'connectors_ai_' . str_replace( '-', '_', $id ) . '_api_key'; + if ( ! empty( $args['authentication']['setting_name'] ) && is_string( $args['authentication']['setting_name'] ) ) { + $connector['authentication']['setting_name'] = $args['authentication']['setting_name']; + } else { + $connector['authentication']['setting_name'] = 'connectors_ai_' . str_replace( '-', '_', $id ) . '_api_key'; + }
This is fully backwards-compatible: connectors that do not provide a custom setting_name continue to receive the auto-generated value.
PR: https://github.com/WordPress/wordpress-develop/pull/11357
Change History (14)
This ticket was mentioned in PR #11357 on WordPress/wordpress-develop by @jorgefilipecosta.
3 months ago
#1
#3
@
3 months ago
I'll follow up later with a new test case so this change lands before the next RC.
#4
@
3 months ago
- Owner set to jorgefilipecosta
- Resolution set to fixed
- Status changed from new to closed
In 62116:
This ticket was mentioned in PR #11378 on WordPress/wordpress-develop by @gziolo.
3 months ago
#5
- Keywords has-unit-tests added
## Summary
- Validate
setting_namein connector registration — reject invalid values with_doing_it_wrong()instead of silently falling back to auto-generated names. - Update PHPDoc to reflect current behavior — widen
typefrom literal'ai_provider'tonon-empty-string, documentsetting_namein@param. - Change auto-generated
setting_namepattern fromconnectors_ai_{$id}_api_keytoconnectors_{$type}_{$id}_api_keyso it works for any connector type. Built-in AI providers infer their names using the existingconnectors_ai_{$id}_api_keyconvention. - Add
constant_nameandenv_var_nameas optional authentication fields, allowing connectors to declare explicit PHP constant and environment variable names for API key lookup. - Refactor
_wp_connectors_get_api_key_source()to accept explicitenv_var_nameandconstant_nameparameters instead of deriving them from the provider ID. - Generalize REST dispatch, settings registration, and script module data to work with all connector types, not just
ai_provider.
## Test plan
- [ ] Verify existing AI provider connectors retain their
connectors_ai_{id}_api_keysetting names - [ ] Register a custom non-AI connector type and verify auto-generated setting name uses
connectors_{type}_{id}_api_key - [ ] Verify
constant_nameandenv_var_nameare stored when provided and omitted when not - [ ] Verify invalid
setting_name,constant_name, andenv_var_namevalues trigger_doing_it_wrong() - [ ] Verify API key masking works for non-AI connector types in REST responses
- [ ] Verify settings registration skips already-registered settings
- [ ] Run full connector test suite:
npm run test:php -- --filter=Tests_Connectors
See also: https://github.com/WordPress/gutenberg/pull/76828
🤖 Generated with Claude Code
This ticket was mentioned in PR #11399 on WordPress/wordpress-develop by @jorgefilipecosta.
3 months ago
#8
## Summary
Register Akismet Anti-Spam as a built-in non-AI connector with spam_filtering type.
- Uses the existing
wordpress_api_keyWordPress option for API key storage - Checks the
WPCOM_API_KEYPHP constant - Skips
register_setting()since Akismet already registerswordpress_api_key
See also: https://github.com/WordPress/gutenberg/pull/76828
#9
@
3 months ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening to include [62180] in the 7.0 branch.
@bluefuton commented on PR #11399:
3 months ago
#10
@gziolo commented on PR #11399:
3 months ago
#11
@bluefuton, can we change the copy to a more generic version, like:
You can manage it at akismet.com
@bluefuton commented on PR #11399:
3 months ago
#12
@bluefuton, can we change the copy to a more generic version, like:
You can manage it at akismet.com
We'd be happy with a more generic version @gziolo 👍 In Akismet's case you can't really do anything with your API key on akismet.com (other than copy it), so maybe something like this?
_You can manage your account at akismet.com_
#14
@
6 weeks ago
@jorgefilipecosta Please remember to follow the commit message guidelines https://make.wordpress.org/core/handbook/best-practices/commit-messages/ so that it's easy to track what has been merged.
## Summary
WP_Connector_Registry::register()always auto-generates thesetting_nameforapi_keyconnectors, ignoring any caller-provided value in$args['authentication']['setting_name']setting_namein the provided args before falling back to the auto-generated nameTrac ticket: https://core.trac.wordpress.org/ticket/64957
## Test plan
setting_nameand verify it is preserved in the registry outputsetting_namestill get the auto-generated value