Skip to content

Commit 3445c0c

Browse files
gzioloclaude
andcommitted
Connectors: Preserve AI Client registry data precedence over hardcoded defaults.
Merges AI Client registry values on top of hardcoded defaults before registering, so provider plugin data takes precedence while hardcoded values serve as fallbacks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 32fb26a commit 3445c0c

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

src/wp-includes/connectors.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,8 @@ function _wp_register_default_connectors(): void {
205205
),
206206
);
207207

208-
// Register built-in connectors first.
209-
foreach ( $defaults as $id => $args ) {
210-
wp_register_connector( $id, $args );
211-
}
212-
213-
// Register connectors from the AI Client registry.
208+
// Merge AI Client registry data on top of defaults.
209+
// Registry values (from provider plugins) take precedence over hardcoded fallbacks.
214210
$ai_registry = AiClient::defaultRegistry();
215211

216212
foreach ( $ai_registry->getRegisteredProviderIds() as $connector_id ) {
@@ -233,20 +229,32 @@ function _wp_register_default_connectors(): void {
233229
$name = $provider_metadata->getName();
234230
$description = $provider_metadata->getDescription();
235231

236-
if ( wp_has_connector( $connector_id ) ) {
237-
// Already registered as a built-in; skip to avoid duplicate registration error.
238-
continue;
239-
}
240-
241-
wp_register_connector(
242-
$connector_id,
243-
array(
232+
if ( isset( $defaults[ $connector_id ] ) ) {
233+
// Override fields with non-empty registry values.
234+
if ( $name ) {
235+
$defaults[ $connector_id ]['name'] = $name;
236+
}
237+
if ( $description ) {
238+
$defaults[ $connector_id ]['description'] = $description;
239+
}
240+
// Always update auth method; keep existing credentials_url as fallback.
241+
$defaults[ $connector_id ]['authentication']['method'] = $authentication['method'];
242+
if ( ! empty( $authentication['credentials_url'] ) ) {
243+
$defaults[ $connector_id ]['authentication']['credentials_url'] = $authentication['credentials_url'];
244+
}
245+
} else {
246+
$defaults[ $connector_id ] = array(
244247
'name' => $name ? $name : ucwords( $connector_id ),
245248
'description' => $description ? $description : '',
246249
'type' => 'ai_provider',
247250
'authentication' => $authentication,
248-
)
249-
);
251+
);
252+
}
253+
}
254+
255+
// Register all connectors.
256+
foreach ( $defaults as $id => $args ) {
257+
wp_register_connector( $id, $args );
250258
}
251259
}
252260

0 commit comments

Comments
 (0)