[wp-trac] [WordPress Trac] #64957: Connectors: `WP_Connector_Registry::register()` ignores custom `setting_name`
WordPress Trac
noreply at wordpress.org
Thu Mar 26 11:31:43 UTC 2026
#64957: Connectors: `WP_Connector_Registry::register()` ignores custom
`setting_name`
------------------------------+-----------------------
Reporter: jorgefilipecosta | Owner: (none)
Type: defect (bug) | Status: new
Priority: high | Milestone: 7.0
Component: General | Version: trunk
Severity: normal | Keywords: has-patch
Focuses: |
------------------------------+-----------------------
`WP_Connector_Registry::register()` always auto-generates the
`setting_name` for connectors that use `api_key` authentication:
{{{#!php
$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 ===
1. Register a connector with a custom `setting_name`:
{{{#!php
$registry->register( 'my-connector', array(
'name' => 'My Connector',
'type' => 'ai_provider',
'authentication' => array(
'method' => 'api_key',
'setting_name' => 'my_existing_option',
),
) );
}}}
2. Retrieve the connector: `wp_get_connector( 'my-connector' )`
3. 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:
{{{#!diff
- $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
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64957>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list